How to align equations in LaTeX

Load amsmath and usealign. Put &before the character to line up on, and end each row with\\.

align.tex
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
  (a+b)^2 &= (a+b)(a+b) \\
          &= a^2 + 2ab + b^2
\end{align}
\end{document}

Both rows line up on the equals sign, because the & sits just before it. align is a math environment of its own. Do not put it inside equation or $ $.

The alignment environments

EnvironmentUse
alignSeveral equations, aligned on a chosen point, each numbered.
align*The same, with no numbers.
gatherSeveral equations, each centred, no alignment.
multlineOne long equation broken over lines.
splitOne long equation aligned, inside equation, with a single number.
alignedAn aligned block inside another math environment.

Numbering and references

align numbers every row. Suppress a number with\notag on that row, or use align* to suppress all of them. Add \label{...} to a numbered row and refer to it with \eqref{...}, which adds the parentheses for you.

label.tex
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
  f(x) &= x^2 + 2x + 1 \label{eq:expanded} \\
       &= (x+1)^2      \label{eq:factored} \\
  f(-1) &= 0           \notag
\end{align}
By \eqref{eq:factored}, the root is $x=-1$.
\end{document}

Compile twice so the numbers resolve. After the first run you will see?? where the references go.

Several columns of equations

Each extra pair of & adds a column. The first& in a pair aligns, the second separates columns. Use it to set two equations side by side.

columns.tex
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
  x + y &= 3 & x - y &= 1 \\
  2x    &= 4 & y     &= 1
\end{align*}
\end{document}

One number for several rows

Use aligned inside equation, orsplit. Both give a single number, centred vertically on the block.

aligned.tex
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
\begin{aligned}
  a &= b + c \\
    &= d
\end{aligned}
\end{equation}

\begin{equation}
\begin{split}
  a &= b + c \\
    &= d
\end{split}
\end{equation}
\end{document}

Use split as the whole body of the equation. Use aligned when the block must sit beside other material, such as a brace or a second block.

Centred rows with gather

When the equations have nothing to line up, gather centres each row. It has no &.

gather.tex
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{gather*}
  x = 1 \\
  y + z = 22
\end{gather*}
\end{document}

Common mistakes

Templates that use this

Multi-line derivations belong in papers and dissertations. See theamsart article, thesimple thesis, or theacademic journal templates.

Related

The right-hand sides usually containfractions,sums and integrals ormatrices. Browsethesis templates andarticle templates for documents that set up equation numbering already, or start withLaTeX for beginners.