Skip to content
EasyLaTeXDocs

Multiline Equations and Alignment

Use align to align multiline formulas at the equals sign, plus sign, or other positions; use align* to create an unnumbered version. Long derivations should be broken into lines according to logical steps, rather than shrinking the font or forcing everything into a single line.

EasyLaTeX compiler setting: pdfLaTeX + article; need to load amsmath.

Basic Alignment

In align, & marks the alignment position, and \\ ends a line:

latex
\begin{align}
  (x+1)^2 &= x^2 + 2x + 1, \\
  (x-1)^2 &= x^2 - 2x + 1.
\end{align}

The example above aligns the two equal signs and generates a number for each line. The alignment point is generally placed before the equal sign, relation symbol, or operator; do not treat & as ordinary characters and write it into the formula.

Unnumbered Alignment

For derivations that do not require citation, use the starred version:

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

The spaces before the second line only make the source file easier to read and do not affect the PDF; what really determines the alignment is &.

A Group of Formulas Is Numbered Only Once

When the entire group of derivations requires only one number, use equation to enclose aligned:

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

aligned can only be embedded in a mathematical environment; it does not itself generate an independent number. Conversely, align is already a standalone display environment and should not be nested inside equation.

Alignment Within Formulas

For multiple definitions, constraints, or explanations, aligned may be used:

latex
\[
  \begin{aligned}
    x + y &= 10, \\
    x - y &= 2.
  \end{aligned}
\]

This syntax is suitable for grouped equations that do not need numbering. If every line needs numbering, use align.

Line Breaks and Markers

When you do not want a particular line to display a number, add \notag at the end of the line:

latex
\begin{align}
  f(x) &= x^2 + 2x + 1 \notag \\
       &= (x+1)^2.
\end{align}

When each step needs to be explained, place the English explanation outside the formula, or use \text{...}. Do not make the formula carry paragraph-length explanations by stacking a large amount of text after the equals sign.

Common Misuses

& Inconsistent quantities

Rows in the same align environment should have the same alignment structure. When the Extra alignment tab has been changed to \cr error occurs, check whether a row has one extra or one fewer &.

Nesting align within equation

align will display and number itself. If you only want a single number, use the combination of equation and aligned.

Using eqnarray

eqnarray is an old environment, and the spacing around operators is not ideal. The new documentation uses environments such as align, gather, and multline provided by amsmath.

Complete Example

latex
\documentclass[a4paper,12pt]{article}
\usepackage{amsmath}

\begin{document}

Number every line:
\begin{align}
  (x+1)^2 &= x^2 + 2x + 1, \\
  (x-1)^2 &= x^2 - 2x + 1.
\end{align}

One number for the whole group:
\begin{equation}
\begin{aligned}
  f(x) &= x^2 + 2x + 1 \\
       &= (x+1)^2.
\end{aligned}
\end{equation}

\end{document}