> 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/vi/toan-hoc/06-aligning-equations-with-amsmath.md).

# Căn chỉnh các phương trình

## Giới thiệu

Tính năng `amsmath` gói này cung cấp một số tùy chọn để hiển thị các phương trình. Bạn có thể chọn bố cục phù hợp hơn với tài liệu của mình, ngay cả khi các phương trình rất dài, hoặc nếu bạn phải chèn nhiều phương trình trên cùng một dòng.

Các công cụ LaTeX chuẩn cho phương trình có thể thiếu một số tính linh hoạt, gây chồng lấn hoặc thậm chí cắt bớt một phần của phương trình khi nó quá dài. Ta có thể vượt qua những khó khăn như vậy bằng cách sử dụng `amsmath` gói, có thể được thêm vào phần tiền đề của tài liệu của bạn bằng `\usepackage{amsmath}`.

Hãy bắt đầu với một ví dụ cơ bản:

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

[Mở `amsmath` đoạn mã trong Overleaf](https://www.overleaf.com/docs?engine=\&snip_name=amsmath+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bamsmath%7D%0A%5Ctitle%7BAmsmath+example%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cdate%7BMay+2021%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cmaketitle%0A%5Csection%7BIntroduction%7D%0A%5Cbegin%7Bequation%7D+%5Clabel%7Beq1%7D%0A%5Cbegin%7Bsplit%7D%0AA+%26+%3D+%5Cfrac%7B%5Cpi+r%5E2%7D%7B2%7D+%5C%5C%0A+%26+%3D+%5Cfrac%7B1%7D%7B2%7D+%5Cpi+r%5E2%0A%5Cend%7Bsplit%7D%0A%5Cend%7Bequation%7D%0A%5Cend%7Bdocument%7D)

Hình minh họa sau cho thấy kết quả do mã LaTeX tạo ra:

![Amsmath-eqn1.png](/files/6801c4d5cc0568d3b730a7a0c3438fc302070201)

Bạn phải bọc phương trình của mình trong `equation` môi trường nếu bạn muốn nó được đánh số, sử dụng `equation*` (có dấu sao) nếu không. Bên trong môi trường `equation` môi trường, sử dụng `split` môi trường để tách các phương trình thành những phần nhỏ hơn, những phần nhỏ hơn này sẽ được căn chỉnh tương ứng. Dấu gạch chéo kép hoạt động như ký tự xuống dòng. Hãy dùng ký tự dấu và `&`, để đặt các điểm mà tại đó các phương trình được căn chỉnh theo chiều dọc.

## Viết một phương trình đơn

Để hiển thị một phương trình đơn, như đã đề cập trong phần giới thiệu, bạn phải dùng `equation*` hoặc `equation` môi trường, tùy thuộc vào việc bạn muốn phương trình có được đánh số hay không. Ngoài ra, bạn có thể thêm một nhãn để tham chiếu sau này trong tài liệu.

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

Phương trình đẹp \ref{eu_eqn} được gọi là phương trình Euler.
```

[Mở `amsmath` đoạn mã trong Overleaf](https://www.overleaf.com/docs?engine=\&snip_name=amsmath+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bamsmath%7D%0A%5Ctitle%7BAmsmath+example%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cdate%7BMay+2021%7D%0A%5Cbegin%7Bdocument%7D%0A%25%5Cmaketitle%0A%25%5Csection%7BIntroduction%7D%0A%5Cbegin%7Bequation%7D+%5Clabel%7Beu_eqn%7D%0Ae%5E%7B%5Cpi+i%7D+%2B+1+%3D+0%0A%5Cend%7Bequation%7D%0A%0AThe+beautiful+equation+%5Cref%7Beu_eqn%7D+is+known+as+the+Euler+equation.%0A%5Cend%7Bdocument%7D)

Hình minh họa sau cho thấy kết quả do mã LaTeX tạo ra:

![Neweuler1.png](/files/addc31857c32daa3214efa1a3b34a06925103309)

Bạn cũng có thể [mở một ví dụ đầy đủ hơn về gói `amsmath` trong Overleaf.](https://www.overleaf.com/project/new/template/19716?id=66719097\&templateName=Amsmath+example\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=)

## Hiển thị các phương trình dài

Đối với các phương trình dài hơn một dòng, hãy dùng `multline` môi trường. Chèn một dấu gạch chéo kép để đặt điểm ngắt phương trình. Phần đầu tiên sẽ được căn trái và phần thứ hai sẽ được hiển thị ở dòng tiếp theo và căn phải.

Một lần nữa, việc dùng dấu sao \* trong tên môi trường quyết định phương trình có được đánh số hay không.

```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*}
```

[Mở phương trình nhiều dòng này `amsmath` đoạn mã trong Overleaf](https://www.overleaf.com/docs?engine=\&snip_name=amsmath+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bamsmath%7D%0A%5Ctitle%7BAmsmath+example%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cdate%7BMay+2021%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cmaketitle%0A%5Csection%7BIntroduction%7D%0A%5Cbegin%7Bmultline%2A%7D%0Ap%28x%29+%3D+3x%5E6+%2B+14x%5E5y+%2B+590x%5E4y%5E2+%2B+19x%5E3y%5E3%5C%5C+%0A-+12x%5E2y%5E4+-+12xy%5E5+%2B+2y%5E6+-+a%5E3b%5E3%0A%5Cend%7Bmultline%2A%7D%0A%5Cend%7Bdocument%7D)

Hình minh họa sau cho thấy kết quả do mã LaTeX tạo ra:

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

Bạn cũng có thể [mở một ví dụ đầy đủ hơn về gói `amsmath` trong Overleaf.](https://www.overleaf.com/project/new/template/19716?id=66719097\&templateName=Amsmath+example\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=)

## Tách và căn chỉnh một phương trình

*Tách* rất giống với *multline*. Hãy dùng *split* môi trường để ngắt một phương trình và căn chỉnh nó theo cột, như thể các phần của phương trình nằm trong một bảng. Môi trường này phải được dùng bên trong một *equation* môi trường. Để xem ví dụ, hãy kiểm tra phần giới thiệu của tài liệu này.

## Căn chỉnh nhiều phương trình

Nếu có nhiều phương trình mà bạn cần căn chỉnh theo chiều dọc, *align* môi trường sẽ làm điều đó:

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

[Mở `amsmath` đoạn mã trong Overleaf](https://www.overleaf.com/docs?engine=\&snip_name=amsmath+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bamsmath%7D%0A%5Ctitle%7BAmsmath+example%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cdate%7BMay+2021%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cmaketitle%0A%5Csection%7BIntroduction%7D%0A%5Cbegin%7Balign%2A%7D+%0A2x+-+5y+%26%3D++8+%5C%5C+%0A3x+%2B+9y+%26%3D++-12%0A%5Cend%7Balign%2A%7D%0A%5Cend%7Bdocument%7D)

Hình minh họa sau cho thấy kết quả do mã LaTeX tạo ra:

![Amsmatheqn4OLV2.png](/files/0f748054971d238d34687dd6923b6534467ef550)

Thông thường các toán tử nhị phân (`>`, `<` và `=`) là những thứ được căn chỉnh để tài liệu trông đẹp mắt.

Như đã nói trước đó, ký tự dấu và `&` quyết định vị trí các phương trình được căn chỉnh. Hãy xem một ví dụ phức tạp hơn:

```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*}
```

[Mở `amsmath` đoạn mã trong Overleaf](https://www.overleaf.com/docs?engine=\&snip_name=amsmath+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bamsmath%7D%0A%5Ctitle%7BAmsmath+example%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cdate%7BMay+2021%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cmaketitle%0A%5Csection%7BIntroduction%7D%0A%5Cbegin%7Balign%2A%7D%0Ax%26%3Dy+++++++++++%26++w+%26%3Dz++++++++++++++%26++a%26%3Db%2Bc%5C%5C%0A2x%26%3D-y+++++++++%26++3w%26%3D%5Cfrac%7B1%7D%7B2%7Dz+++%26++a%26%3Db%5C%5C%0A-4+%2B+5x%26%3D2%2By+++%26++w%2B2%26%3D-1%2Bw++++++++++%26++ab%26%3Dcb%0A%5Cend%7Balign%2A%7D%0A%5Cend%7Bdocument%7D)

Hình minh họa sau cho thấy kết quả do mã LaTeX tạo ra:

![Amsmath-eqn6OLV2.png](/files/eef5ce0f8397ed692eda9d477a0f1f97a3238d12)

Ở đây chúng ta sắp xếp các phương trình thành ba cột. LaTeX giả định rằng mỗi phương trình gồm hai phần được ngăn cách bởi một `&` và rằng mỗi phương trình được tách khỏi phương trình trước bởi một `&`.

Một lần nữa, dùng \* để bật/tắt việc đánh số phương trình. Khi cho phép đánh số, bạn có thể gán nhãn cho từng hàng riêng lẻ.

## Nhóm và căn giữa các phương trình

Nếu bạn chỉ cần hiển thị một tập hợp các phương trình liên tiếp, được căn giữa và hoàn toàn không có căn chỉnh gì, hãy dùng `gather` môi trường. Mẹo dùng dấu sao để bật/tắt việc đánh số phương trình cũng hoạt động ở đây.

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

[Mở `amsmath` đoạn mã trong Overleaf](https://www.overleaf.com/docs?engine=\&snip_name=amsmath+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bamsmath%7D%0A%5Ctitle%7BAmsmath+example%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cdate%7BMay+2021%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cmaketitle%0A%5Csection%7BIntroduction%7D%0A%5Cbegin%7Bgather%2A%7D+%0A2x+-+5y+%3D++8+%5C%5C+%0A3x%5E2+%2B+9y+%3D++3a+%2B+c%0A%5Cend%7Bgather%2A%7D%0A%5Cend%7Bdocument%7D)

Hình minh họa sau cho thấy kết quả do mã LaTeX tạo ra:

![Amsmath-eqn5.png](/files/959b8e806ddc250d6d8b81b0a4738be98cbd8a09)

## Đọc thêm

Để biết thêm thông tin, xem

* [Biểu thức toán học](/latex/vi/toan-hoc/01-mathematical-expressions.md)
* [Dấu ngoặc và ngoặc tròn](/latex/vi/toan-hoc/03-brackets-and-parentheses.md)
* [Chỉ số dưới và chỉ số trên](/latex/vi/toan-hoc/02-subscripts-and-superscripts.md)
* [Khoảng cách trong chế độ toán học](/latex/vi/toan-hoc/08-spacing-in-math-mode.md)
* [Kiểu hiển thị trong chế độ toán học](/latex/vi/toan-hoc/10-display-style-in-math-mode.md)
* [Phông chữ toán học](/latex/vi/toan-hoc/12-mathematical-fonts.md)
* [Danh sách các chữ cái Hy Lạp và ký hiệu toán học](/latex/vi/toan-hoc/11-list-of-greek-letters-and-math-symbols.md)
* [Các toán tử](/latex/vi/toan-hoc/07-operators.md)
* [Phân số và nhị thức](/latex/vi/toan-hoc/05-fractions-and-binomials.md)
* [tài liệu gói 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/vi/toan-hoc/06-aligning-equations-with-amsmath.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.
