> 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-tw/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/15c47e6396b32b98557a7fbeda4ff50bca80634c)

方程式必須包含在環境 *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/9041a2205f4f94d8dfe65f0435766bd0bde57994)

[開啟 amsmath 套件的 Overleaf 範例](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/154fe96446013de8686216be3aa1cfebfdb5a6fc)

[在 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/0f4479be9110c7af667b1e7b168a4c3385530080)

通常會將二元運算子（>、< 和 =）當作垂直對齊點，這樣可使文件在視覺上更美觀。

如前所述，與號 *&* 決定方程式的對齊點。讓我們看一個稍微更複雜的範例：

```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/b2701489f06a5ce153461af5245ad0fd6a30c1b0)

這裡方程式被排列成三欄。LaTeX 會假設每個方程式由兩個部分組成，並以字元 *&*；而且每個方程式又由前一個方程式以一個 *&*.

同樣地，也可以使用星號 \* 來啟用或停用方程式編號。當編號啟用時，可以為每一行分別加上標籤。

[開啟 amsmath 套件的 Overleaf 範例](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/d70ee49d7bc125d24fcab889a1885b1878f0137f)

[在 Overleaf 中開啟 amsmath 套件範例](https://www.sharelatex.com/project/new/template?zipUrl=/project/52e1889fd3e596077700148c/download/zip\&templateName=Amsmath_Example_Project\&compiler=pdflatex)

## 延伸閱讀

更多資訊請參閱：

* [數學表達式](/latex/zh-tw/shu-xue/01-mathematical-expressions.md)
* [中括號與小括號](/latex/zh-tw/shu-xue/03-brackets-and-parentheses.md)
* [下標與上標](/latex/zh-tw/shu-xue/02-subscripts-and-superscripts.md)
* [數學模式中的間距](/latex/zh-tw/shu-xue/08-spacing-in-math-mode.md)
* [數學模式中的顯示樣式](/latex/zh-tw/shu-xue/10-display-style-in-math-mode.md)
* [數學字型](/latex/zh-tw/shu-xue/12-mathematical-fonts.md)
* [希臘字母與數學符號列表](/latex/zh-tw/shu-xue/11-list-of-greek-letters-and-math-symbols.md)
* [運算子](/latex/zh-tw/shu-xue/07-operators.md)
* [分數與二項式](/latex/zh-tw/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-tw/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.
