Math and Equations

Aligning Equations in LaTeX with align

Align multi-line equations in LaTeX with the amsmath align environment, covering line numbers, notag to hide them, intertext, and systems of equations.

On this page
  1. Basic align
  2. align versus align*
  3. Other amsmath alignment environments
  4. Systems of equations
  5. Text between aligned lines
  6. Common mistakes

Long derivations read better when the equals signs line up. The align environment from amsmath does this. Each & marks an alignment point, and \\ starts a new line.

Basic align

\begin{align*}
  f(x) &= (x+1)^2 - 1 \\
       &= x^2 + 2x + 1 - 1 \\
       &= x^2 + 2x
\end{align*}

The & goes before each =, so the equals signs line up down the page. The lines do not need to be the same length.

align versus align*

  • align numbers every line.
  • align* prints no numbers.
  • \notag or \nonumber removes the number from one line of an align.
  • \label on a line gives that line a reference.
\begin{align}
  a^2 + b^2 &= c^2 \label{eq:pythagoras} \\
  c &= \sqrt{a^2 + b^2} \notag
\end{align}

The first line can be cited in the text as \eqref{eq:pythagoras}. How to label an equation covers references in more detail.

Other amsmath alignment environments

Environment Use it for
aligned Alignment inside another math environment, such as equation or \[ \], with one number for the whole block
gather Lines centered on the page, with no alignment point
multline One long equation broken across lines, with the first line flush left and the last line flush right
split One long equation inside equation, with one number
alignat Alignment with several columns and custom spacing

Systems of equations

Put aligned inside \left\{ ... \right. to get one brace over several equations that line up at the equals sign:

\[
  \left\{
  \begin{aligned}
    2x + y &= 7 \\
    x - y  &= 2
  \end{aligned}
  \right.
\]

The \right. closes the brace without printing one. The solution is $x = 3$ and $y = 1$. Sizing brackets and parentheses covers the delimiter pairs in more detail.

Text between aligned lines

\intertext{...} adds a line of text between aligned lines without breaking the alignment:

\begin{align*}
  x + y &= 5 \\
  \intertext{Substituting $x = 2$ into the first equation gives}
  y &= 3
\end{align*}

Common mistakes

  • Blank lines inside the environment cause a compilation error. If you want visual space in the source, put a % on a line by itself.
  • Too many & characters in one line add an extra alignment column and produce an “Extra alignment tab” error.
  • Math mode inside align: do not wrap align in $$ or \[ \]. The environment is already display math.
  • eqnarray: the older environment spaces the middle column differently and handles numbering poorly. Use align instead.
  • Missing amsmath: align is not defined without the package, so load amsmath in the preamble.

For the matrix and determinant environments that often sit inside an aligned block, see matrices and determinants.

The complete guide to math and equations

Advanced Mathematics in LaTeX: Operators, Theorems and Proofs
Read the guide

Keep exploring

Guides from other topics

All topics →