> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/zh-cn/geng-duo-zhu-ti/03-aligning-equations-with-amsmath-es.md).

# 使用 amsmath 对齐方程 es

该宏包 **amsmath** 提供了相当丰富的公式排版选项。你可以选择最适合文档的方程布局，即使方程非常大，或者需要在同一行中包含多个方程时也可以。

## 简介

LaTeX 用于处理方程的标准工具缺乏灵活性，导致有时元素会重叠，甚至在方程过大时截断方程元素。所有这些困难都可以通过宏包 **amsmath**。我们先从一个示例开始：

```latex
\begin{equation} \label{eq1}
\begin{split}
A & = \frac{\pi r^2}{2} \\
 & = \frac{1}{2} \pi r^2
\end{split}
\end{equation}
```

![Amsmath-eqn1.png](/files/7f5d9a9a59161a0042b0c1955edef9d23077f7ea)

该方程应包含在环境 *equation* 如果需要显示编号，可以使用 *equation\** （带星号），如果不希望编号。在环境 *equation* 中使用环境 *split* 用于将方程拆分为更小的部分，这些部分会自动对齐。使用双反斜杠（double backslash）可作为换行符。et 符号（也以英文名 ampersand 为人所知） *&* 用于设置方程垂直对齐的基准点。

[在 Overleaf 中打开 amsmath 宏包示例](https://www.sharelatex.com/project/new/template?zipUrl=/project/52e1889fd3e596077700148c/download/zip\&templateName=Amsmath_Example_Project\&compiler=pdflatex)

## 导入 amsmath 宏包

这一步非常简单，如果你经常使用 LaTeX，可能已经知道这一点。要导入宏包“*amsmath*”，请在文档导言区添加以下代码行。

`\usepackage{amsmath}`

[在 Overleaf 中打开 amsmath 宏包示例](https://www.sharelatex.com/project/new/template?zipUrl=/project/52e1889fd3e596077700148c/download/zip\&templateName=Amsmath_Example_Project\&compiler=pdflatex)

## 编写单个方程

要显示一个单独的方程，正如简介中所述，应使用环境 *equation\** 用于无编号方程，或者使用环境 *equation* 用于有编号方程。此外，还可以通过命令添加标签 `\label`，该标签之后可以在文档中引用。

```latex
\begin{equation} \label{eu_eqn}
e^{\pi i} - 1 = 0
\end{equation}

优美的方程 \ref{eu_eqn} 被称为欧拉方程
```

![Amsmath-eqn2.png](/files/26ff3c563b181a8835aefd9b3939bba69bf8aee9)

[在 Overleaf 中打开 amsmath 宏包示例](https://www.sharelatex.com/project/new/template?zipUrl=/project/52e1889fd3e596077700148c/download/zip\&templateName=Amsmath_Example_Project\&compiler=pdflatex)

## 插入多行方程

要创建跨越多行的方程，应使用环境 *multline*。需要插入双反斜杠来指定方程分割的位置。第一部分将左对齐，而另一部分会显示在下一行并右对齐。

与其他命令类似，可以在环境名称后加星号来决定方程是否编号。

```latex
\begin{multline*}
p(x) = 3x^6 + 14x^5y + 590x^4y^2 + 19x^3y^3\\
- 12x^2y^4 - 12xy^5 + 2y^6 - a^3b^3
\end{multline*}
```

![Amsmath-eqn3.png](/files/b4866ada4ac89925aa29fb0f29cccd23074f3766)

[在 Overleaf 中打开 amsmath 宏包示例](https://www.sharelatex.com/project/new/template?zipUrl=/project/52e1889fd3e596077700148c/download/zip\&templateName=Amsmath_Example_Project\&compiler=pdflatex)

## 拆分并对齐方程

*split* 是一个与……非常相似的环境 *multline*。环境 *split* 用于将一个方程拆分为多个部分，然后按列对齐，就像方程的各部分位于一个表格中一样。该环境必须在环境 *equation*中使用。要查看示例，请参见本文开头的简介部分。

## 对齐多个方程

如果有多个方程需要垂直对齐，环境 *align* 负责处理：

```latex
\begin{align*}
2x - 5y &=  8 \\
3x + 9y &=  -12
\end{align*}
```

![Amsmath-eqn4.png](/files/4b147bce96d43560058947eb105067385ed07787)

通常将二元运算符（>、< 和 =）作为垂直对齐点，这样可以得到视觉上更美观的文档。

如前所述，et 符号 *&* 决定方程的对齐点。让我们看一个稍微复杂一些的例子：

```latex
\begin{align*}
x&=y           &  w &=z              &  a&=b+c\\
2x&=-y         &  3w&=\frac{1}{2}z   &  a&=b\\
-4 + 5x&=2+y   &  w+2&=-1+w          &  ab&=cb
\end{align*}
```

![Amsmath-eqn6.png](/files/b0c8ebe5ed4b8c7e9b708d4fda11eceb833d9508)

这里方程被排列为三列。LaTeX 假定每个方程由两部分组成，这两部分由字符 *&*&#x5206;隔；并且每个方程又通过一个 *&*.

同样，可以使用星号 \* 来启用或禁用方程编号。当编号启用时，可以分别为每一行添加标签。

[在 Overleaf 中打开 amsmath 宏包示例](https://www.sharelatex.com/project/new/template?zipUrl=/project/52e1889fd3e596077700148c/download/zip\&templateName=Amsmath_Example_Project\&compiler=pdflatex)

## 分组并居中方程

如果你只需要显示一系列连续、居中且不进行任何对齐的方程，请使用环境 *gather*。使用星号启用/禁用方程编号的技巧在这里同样适用。

```latex
\begin{gather*}
2x - 5y =  8 \\
3x^2 + 9y =  3a + c
\end{gather*}
```

![Amsmath-eqn5.png](/files/75d81661f13056050166f3c26eff1e481ae63146)

[在 Overleaf 中打开 amsmath 宏包示例](https://www.sharelatex.com/project/new/template?zipUrl=/project/52e1889fd3e596077700148c/download/zip\&templateName=Amsmath_Example_Project\&compiler=pdflatex)

## 延伸阅读

更多信息请参阅：

* [数学表达式](/latex/zh-cn/shu-xue/01-mathematical-expressions.md)
* [括号](/latex/zh-cn/shu-xue/03-brackets-and-parentheses.md)
* [下标和上标](/latex/zh-cn/shu-xue/02-subscripts-and-superscripts.md)
* [数学模式中的间距](/latex/zh-cn/shu-xue/08-spacing-in-math-mode.md)
* [数学模式中的显示样式](/latex/zh-cn/shu-xue/10-display-style-in-math-mode.md)
* [数学字体](/latex/zh-cn/shu-xue/12-mathematical-fonts.md)
* [希腊字母和数学符号列表](/latex/zh-cn/shu-xue/11-list-of-greek-letters-and-math-symbols.md)
* [运算符](/latex/zh-cn/shu-xue/07-operators.md)
* [分数和二项式](/latex/zh-cn/shu-xue/05-fractions-and-binomials.md)
* [amsmath 宏包文档](http://mirrors.ctan.org/macros/latex/required/amsmath/amsmath.pdf)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/zh-cn/geng-duo-zhu-ti/03-aligning-equations-with-amsmath-es.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
