Aligning_equations_with_amsmath
Equation Alignment
The amsmath package provides several options for displaying equations. You can choose layouts that are more suitable for your document, even if the equations are very long, or if you need to include several equations in the same line.
Standard LaTeX tools for equations may lack some flexibility, causing overlaps or even trimming parts of the content when equations are too long. We can overcome these difficulties by using the amsmath package, which can be added to your document's preamble with \usepackage{amsmath}.
Let's start with a basic example:
\begin{equation} \label{eq1}
\begin{split}
A & = \frac{\pi r^2}{2} \\
& = \frac{1}{2} \pi r^2
\end{split}
\end{equation}
Single Equation
To display a single equation, as mentioned in the introduction, you must use the equation* or equation environment, depending on whether you want the equation to be numbered. Additionally, you may add a label for future reference in the document.
\begin{equation} \label{eu_eqn}
e^{\pi i} + 1 = 0
\end{equation}
The beautiful equation \ref{eu_eqn} is known as the Euler equation.
Displaying Long Equations
For equations longer than one line, use the multline environment. Insert a double backslash to set a break point for the equation. The first part will be left-aligned, and the second part will be displayed on the next line and right-aligned.
Similarly, the use of an asterisk * in the environment name determines whether the equation is numbered.
\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*}
Splitting and Aligning Equations
If there are several equations that need to be vertically aligned, the align environment can do this.
\begin{align*}
2x - 5y &= 8 \\
3x + 9y &= -12
\end{align*}
Typically, binary operators (>, <, and =) are aligned to obtain a beautiful document.
As mentioned earlier, the ampersand character & determines the alignment position of the equations. Let's look at a more complex example.
\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*}
Grouping and Centering Equations
\begin{gather*}
2x - 5y = 8 \\
3x^2 + 9y = 3a + c
\end{gather*}