LaTeX Align Equations
Five environments for multi-line math: align, align*, gather, split, equation. Pick by what you need (alignment? numbering? single-equation continuation?).
The decision tree
| What you want | Environment |
|---|---|
| Single numbered equation | equation |
| Single unnumbered equation | equation* or \[ \] |
| Multiple aligned equations, numbered | align |
| Multiple aligned equations, unnumbered | align* |
| Multiple unrelated equations centered | gather |
| One long equation split across lines | equation + split |
align — the most useful one
\usepackage{amsmath}
\begin{align}
a &= b + c \\
d &= e + f + g \\
h &= i
\end{align}The & marks the alignment column (here, the equals signs). Each line ends with \\. The result has all three = signs vertically aligned, with each line numbered (1), (2), (3).
align* — same alignment, no numbers
\begin{align*}
a &= b + c \\
d &= e + f
\end{align*}gather — center each, no alignment
\begin{gather}
a = b + c \\
d = e + f + g
\end{gather}split — one long equation
\begin{equation}
\begin{split}
f(x) &= a_0 + a_1 x + a_2 x^2 \\
&\quad + a_3 x^3 + a_4 x^4 + a_5 x^5
\end{split}
\label{eq:expansion}
\end{equation}Whole thing gets one equation number. Reference with \eqref{eq:expansion}.
Mixed numbering
\begin{align}
a &= 1 \label{eq:first} \\
b &= 2 \nonumber \\
c &= 3 \label{eq:third}
\end{align}Lines 1 and 3 get numbers. Line 2 has \nonumber so it's skipped.
Common mistakes
- Forgetting amsmath. align, gather, split all need
\usepackage{amsmath}. - Trailing
\\on the last line. Causes "Misplaced \noalign" error. Remove it. - Using
eqnarray. Old, deprecated, looks worse than align. Use align. - Forgetting the
&. Without&, align falls back to a single column with no alignment.
$
a &= b + c \
d &= e + f + g \
h &= i
$No \begin/\end, no package import. Just $ ... $ with & for alignment. Try TypeTeX free.
Frequently Asked Questions
Use the align environment from amsmath: \begin{align} a &= b + c \\ d &= e \end{align}. The ampersand & marks the alignment column — the equals signs (or whatever you align on) line up vertically. Each line ends with \\ except the last.
align numbers each line: (1), (2), (3). align* leaves them unnumbered. To suppress numbering on individual lines within align, use \nonumber or \notag at the end of that line.
Use the split environment inside equation: \begin{equation} \begin{split} long expression that doesn't fit \\ continuation \end{split} \end{equation}. The whole thing gets one equation number. Use & to align the continuation.
gather centers each equation independently (no alignment column). Use it when you have multiple unrelated equations that don't need to align: \begin{gather} a = 1 \\ b = 2 \\ c = 3 \end{gather}. align is for related equations; gather is for a list of standalone equations.
Use multiple & in each line: \begin{align} a &= 1 &\quad b &= 2 \\ c &= 3 &\quad d &= 4 \end{align}. The first & aligns the first column, the second & aligns the second. \quad adds horizontal spacing between groups.
You probably used \\ at the end of the last line. The last \\ is unnecessary and causes the error. Remove it and the environment compiles cleanly.
Use align (numbered by default), then add \nonumber or \notag at the end of lines you want unnumbered: a &= 1 \\ b &= 2 \nonumber \\ c &= 3. Lines 1 and 3 get numbers; line 2 doesn't.
Add \label{eq:name} after \\ on the line you want to reference, then use \eqref{eq:name} in text: 'See equation~\eqref{eq:foo} for the result.' \eqref produces (1) automatically — better than \ref which gives just '1'.
Yes, for align, gather, split, eqref, and most multi-line environments. Add \usepackage{amsmath} to your preamble. Most modern LaTeX templates load it by default.