How to Write a Multiline Equation in LaTeX

Break an equation over several lines with amsmath's align: end each line with \\ and put & before the symbol the lines should line up on, usually =. align* drops the numbers. Inside $$ … $$ (Markdown, MathJax) or another equation, use \begin{aligned} … \end{aligned}, which works the same way.

Multiline environments (amsmath)

  • \begin{align} a &= b \\ c &= d \end{align}
    a = b c = d

    Aligned lines, each numbered.

  • \begin{align*} a &= b \\ c &= d \end{align*}
    a = b c = d

    Aligned lines, no numbers.

  • \begin{aligned} a &= b \\ c &= d \end{aligned}
    a = b c = d

    Aligned block inside another display: $$ … $$, equation, \[ … \].

  • \begin{split} a &= b \\ &= c \end{split}
    a = b = c

    One long equation split over lines, one number (use inside equation).

  • \begin{gather} a = b \\ c = d \end{gather}
    a = b c = d

    Several centered lines, no alignment.

  • \begin{multline} a + b + c \\ + d + e \end{multline}
    a + b + c + d + e

    Long equation: first line left, last line right.

  • \begin{alignat}{2} x &= 1 &\quad y &= 2 \end{alignat}
    x = 1 y = 2

    Several alignment columns with spacing you control.

  • a &= b \notag \\
    Text mode, no math preview

    Drop the number of one line in align.

Try it live

Change the formula and the preview redraws as you type. Copy the LaTeX, download a PNG or SVG, copy it for Word, or use Edit here on any example below to load it.

Templates

Multiline equations examples

Each result below is drawn from the LaTeX under it. Copy the code, edit it on this page, or open it in the full editor.

  • Step-by-step derivation

    f ( x ) = x 2 − 6 x + 9 = ( x − 3 ) 2
    LaTeX
    \begin{aligned} f(x) &= x^2 - 6x + 9 \\ &= (x-3)^2 \end{aligned}
  • System of equations

    { 2 x + 3 y = 7 x − y = 1
    LaTeX
    \left\{ \begin{aligned} 2x + 3y &= 7 \\ x - y &= 1 \end{aligned} \right.

    \left\{ … \right. adds the brace on the left and nothing on the right.

  • Aligned with comments

    3 x + 5 = 11 given 3 x = 6 subtract  5 x = 2 divide by  3
    LaTeX
    \begin{aligned} 3x + 5 &= 11 && \text{given} \\ 3x &= 6 && \text{subtract } 5 \\ x &= 2 && \text{divide by } 3 \end{aligned}

    && starts a new column, here used for the explanations.

  • Long equation with multline

    p ( x ) = 3 x 6 + 14 x 5 + 590 x 4 + 19 x 3 − 12 x 2 − 12 x + 5
    LaTeX
    \begin{multline} p(x) = 3x^6 + 14x^5 + 590x^4 + 19x^3 \\ - 12x^2 - 12x + 5 \end{multline}
  • Centered lines with gather

    a 2 + b 2 = c 2 e i π + 1 = 0
    LaTeX
    \begin{gather} a^2 + b^2 = c^2 \\ e^{i\pi} + 1 = 0 \end{gather}
  • Numbered aligned lines

    ∇ ⋅ E = ρ ε 0 ∇ ⋅ B = 0
    LaTeX
    \begin{align} \nabla \cdot \mathbf{E} &= \frac{\rho}{\varepsilon_0} \\ \nabla \cdot \mathbf{B} &= 0 \end{align}

How to align equations

Load \usepackage{amsmath}. In align, each line ends with \\ (not the last one) and & marks the alignment point: a &= b lines up the equals signs. Put the & before the = so the spacing around it stays correct.

Every line of align gets a number; use align* for none or \notag on single lines. More & add further columns, alternating right-aligned and left-aligned, which is how side-by-side equations or comments are laid out.

LaTeX
\begin{align}
  f(x) &= (x+1)^2 \\
       &= x^2 + 2x + 1 \label{eq:expanded}
\end{align}

align, aligned or split?

align is a complete display environment; it cannot sit inside equation or $$. aligned is the building block that goes inside one — which is why Markdown editors, Jupyter and MathJax users write $$\begin{aligned} … \end{aligned}$$.

split also goes inside equation and gives the whole block a single number, the right choice for one long equation broken into lines. gather centers lines without aligning them, and multline spreads one very long formula over lines, first line flush left and last flush right.

Common mistakes

  • equation holds a single line; the \\ is ignored and everything stays on one line.

    Instead of
    \begin{equation}
      a = b \\
      c = d
    \end{equation}
    Write
    \begin{align}
      a &= b \\
      c &= d
    \end{align}
  • eqnarray puts too much space around the = and is discouraged; amsmath's align replaces it.

    Instead of
    \begin{eqnarray}
      a &=& b
    \end{eqnarray}
    Write
    \begin{align}
      a &= b
    \end{align}
  • Nesting align in another display raises "Erroneous nesting of equation structures". Use aligned.

    Instead of
    \begin{equation}
      \begin{align} … \end{align}
    \end{equation}
    Write
    \begin{equation}
      \begin{aligned} … \end{aligned}
    \end{equation}
  • With & after the = the equals sign loses its spacing and the lines align on the wrong edge.

    Instead of
    a =& b
    Write
    a &= b

In Overleaf, MathJax and Word

  • Overleaf and pdfLaTeX

    All environments come from amsmath. A blank line inside align is an error. Page breaks inside align are off by default; \allowdisplaybreaks in the preamble permits them.

  • MathJax and KaTeX

    MathJax supports align, align*, aligned, gather, multline, split and alignat; numbering needs its tags option. KaTeX supports aligned and gathered anywhere and align or gather in display mode. In Markdown apps, $$\begin{aligned} … \end{aligned}$$ is the safe choice.

  • Microsoft Word

    Word aligns multi-line equations inside its own equation box, not from &. Build the aligned block in the editor on this page and use Copy for Word to paste it as one editable equation.

Multiline equations in LaTeX: questions

How do I write a multiline equation in LaTeX?
Use \begin{align*} … \end{align*} from amsmath, end each line with \\, and put & before the = on every line so they line up.
How do I break a long equation into two lines?
Inside equation, wrap it in \begin{split} … \end{split} with \\ at the break and & at the alignment point, or use multline for a very long formula.
What is the difference between align and aligned?
align is a standalone display environment with numbers. aligned goes inside another display (equation, \[ … \], $$ … $$) and the whole block gets at most one number.
How do I number only one line in align?
Add \notag (or \nonumber) to every line that should have no number.
How do I write a system of equations?
Put an aligned block between \left\{ and \right., or use \begin{cases} … \end{cases} for a simple brace on the left.

Have the formula as a picture?

Paste a screenshot or photo of the equation and get its LaTeX, ready to copy or open in the editor.

Convert an image to LaTeX