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.

2x+3=72x=4x=2\begin{align} 2x + 3 &= 7 \\ 2x &= 4 \\ x &= 2 \end{align}

Open this formula in the editor

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.

(a+b)2=(a+b)(a+b)=a2+2ab+b2\begin{align} (a+b)^2 &= (a+b)(a+b) \notag \\ &= a^2 + 2ab + b^2 \end{align}

Open this formula in the editor

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.

x=1y=2z=3x2=1y2=4z2=9\begin{align*} x &= 1 & y &= 2 & z &= 3 \\ x^2 &= 1 & y^2 &= 4 & z^2 &= 9 \end{align*}

Open this formula in the editor

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.

f(x)=(x+1)2=x2+2x+1\begin{equation} \begin{aligned} f(x) &= (x+1)^2 \\ &= x^2 + 2x + 1 \end{aligned} \end{equation}

Open this formula in the editor

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*}
Result
The compiled example

Open in the editor

Pitfalls

Compiled with pdfLaTeX from TeX Live 2023.

Related pages