Align equations in LaTeX (align)
The align environment from amsmath lines up several equations. Put & in front of the character to align at, usually =, and end each line with \\. align* does the same without equation numbers.
Preamble
The snippets on this page need these lines before \begin{document}:
\usepackage{amsmath}Align at the equals sign
Every line gets its own number. align starts math mode itself: do not wrap it in $...$, \[...\] or equation.
\begin{align}
2x + 3 &= 7 \\
2x &= 4 \\
x &= 2
\end{align}Change the formula
The preview is drawn in your browser by KaTeX, which knows the common math commands. The editor compiles the formula with pdfTeX.
Number only some lines
\notag before the \\ removes the number of that line. align* removes all numbers.
\begin{align}
(a+b)^2 &= (a+b)(a+b) \notag \\
&= a^2 + 2ab + b^2
\end{align}Change the formula
The preview is drawn in your browser by KaTeX, which knows the common math commands. The editor compiles the formula with pdfTeX.
Several equations per line
The & signs alternate: the first, third and fifth mark an alignment point, the second and fourth start a new column of equations.
\begin{align*}
x &= 1 & y &= 2 & z &= 3 \\
x^2 &= 1 & y^2 &= 4 & z^2 &= 9
\end{align*}Change the formula
The preview is drawn in your browser by KaTeX, which knows the common math commands. The editor compiles the formula with pdfTeX.
One number for the whole block
aligned aligns in the same way but is used inside another math environment. Inside equation the block gets one number, centred vertically.
\begin{equation}
\begin{aligned}
f(x) &= (x+1)^2 \\
&= x^2 + 2x + 1
\end{aligned}
\end{equation}Change the formula
The preview is drawn in your browser by KaTeX, which knows the common math commands. The editor compiles the formula with pdfTeX.
Text between the lines
\intertext{...} after a \\ inserts a line of normal text and keeps the alignment of the equations before and after it.
\begin{align*}
a &= b + c \\
\intertext{and therefore}
a - c &= b
\end{align*}Pitfalls
- An empty line inside
alignstops with "Paragraph ended before \align was complete", see Paragraph ended before \label was complete. Delete the empty line or start it with%. - Do not put
\\after the last line. It adds an empty line that gets an equation number of its own. eqnarrayis outdated: it puts too much space around the=. Usealigninstead.
Compiled with pdfLaTeX from TeX Live 2023.