Aligning equations in LaTeX: align, aligned and split

Help centre › LaTeX › Equations · Packages: amsmath

Load \usepackage{amsmath} and write the lines inside \begin{align} … \end{align}, putting & just before the symbol to align on (usually &=) and \\ between lines. Every line of align gets a number; use align* for none, \notag on a line to drop its number, or aligned/split inside equation for one number for the whole block.

A complete example

A whole document: paste it into an empty project and compile it.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
Each line gets its own number:
\begin{align}
  f(x) &= (x+1)^2 \label{eq:square}\\
       &= x^2 + 2x + 1 \notag\\
  g(x) &= 3x - 4 \label{eq:line}
\end{align}
One number for a derivation:
\begin{equation}
  \begin{split}
    (a+b)^2 &= (a+b)(a+b)\\
            &= a^2 + 2ab + b^2
  \end{split}
  \label{eq:binomial}
\end{equation}
Equations \eqref{eq:square}, \eqref{eq:line} and \eqref{eq:binomial} are numbered;
the middle line of the first block is not.
\end{document}

Which environment to use

  • align: several equations, each numbered, aligned at &. align\* is the same with no numbers.
  • equation + split: one equation broken over several lines, with a single number centered vertically (or on the last line with the tbtags option of amsmath).
  • equation + aligned: like split, but aligned is a block you can place anywhere in maths, for example beside a brace or inside \left\{ … \right..
  • gather: several equations centered, each numbered, no alignment.
  • multline: one long equation, first line flush left, last line flush right, one number.
  • alignat: several aligned columns with no space added between them, for systems of equations.

Numbering only some lines

Inside align and gather, \notag (or \nonumber) on a line removes its number. To number a whole derivation once, put \notag on every line but the one that should carry the number, or use split inside equation.

\tag{*} replaces a line's number with your own text; \tag*{…} does the same without parentheses. To number related lines 1a, 1b, 1c, wrap the align in subequations:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{subequations}\label{eq:system}
\begin{align}
  x + y &= 3 \label{eq:first}\\
  x - y &= 1 \label{eq:second}
\end{align}
\end{subequations}
System \eqref{eq:system} has the lines \eqref{eq:first} and \eqref{eq:second}.
\begin{align}
  E &= mc^2 \tag{$\ast$}
\end{align}
\end{document}

Several columns of alignment

Each extra pair of & starts a new aligned column. In align the columns are spread apart; in alignat{n} (n = number of equation columns) you control the space yourself.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
  a &= b + c, & d &= e - f\\
  u &= v,     & w &= x + y + z
\end{align}
\begin{alignat}{2}
  3x &{}+{}& 2y &= 7\\
   x &{}-{}&  y &= 1
\end{alignat}
\end{document}

Text between aligned lines

\intertext{…} puts a line of text between two rows without breaking the alignment: the rows after it stay aligned with the rows before. Write it at the start of a row, after the \\.

\begin{align}
  x &= 2y + 1\\
  \intertext{and, substituting $y = 3$,}
  x &= 7
\end{align}

Brackets that span lines

\left( and \right) must be on the same line of an align. For a bracket that opens on one line and closes on the next, use fixed sizes, \bigl( … \bigr) or \Bigl( … \Bigr), or close each line with an invisible \right. and reopen the next with \left..

Common mistakes

In journal templates

Errors you may meet

  • Paragraph ended before \<name> was complete.A blank line (paragraph break) appeared inside an argument or maths environment that cannot contain one, often because a } or \end{…} is missing.
  • Misplaced alignment tab character &.An & appeared outside a table or align environment. In text write \&; in a bibliography fix the & in the .bib entry; in maths use align.
  • Missing $ inserted.A maths-only character or command (_ ^ \alpha) appeared in text, or text appeared in maths. Wrap the maths in $ … $ or escape the character.
  • LaTeX Error: Environment <name> undefined\begin{…} names an environment no loaded package defines: load the package (amsmath for align), fix the spelling, or define it with \newtheorem.
  • Missing \right. inserted.A \left has no matching \right in the same formula or line, or a \right has no \left. Pair them, or use \right. / \left. as invisible partners.

In Manulyx

Insert → Maths offers inline, display, numbered and aligned maths, writing the environment for you, and the editor previews the maths as you type.

Write in Manulyx for free · Journal templates

Related

The examples on this page were compiled with pdfLaTeX to check that they work as shown. LaTeX quick reference · LaTeX errors explained