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}Aligned lines, each numbered.
\begin{align*} a &= b \\ c &= d \end{align*}Aligned lines, no numbers.
\begin{aligned} a &= b \\ c &= d \end{aligned}Aligned block inside another display:
$$ … $$,equation,\[ … \].\begin{split} a &= b \\ &= c \end{split}One long equation split over lines, one number (use inside
equation).\begin{gather} a = b \\ c = d \end{gather}Several centered lines, no alignment.
\begin{multline} a + b + c \\ + d + e \end{multline}Long equation: first line left, last line right.
\begin{alignat}{2} x &= 1 &\quad y &= 2 \end{alignat}Several alignment columns with spacing you control.
- Text mode, no math preview
a &= b \notag \\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.
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
LaTeX\begin{aligned} f(x) &= x^2 - 6x + 9 \\ &= (x-3)^2 \end{aligned}System of equations
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
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
LaTeX\begin{multline} p(x) = 3x^6 + 14x^5 + 590x^4 + 19x^3 \\ - 12x^2 - 12x + 5 \end{multline}Centered lines with gather
LaTeX\begin{gather} a^2 + b^2 = c^2 \\ e^{i\pi} + 1 = 0 \end{gather}Numbered aligned lines
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.
\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
equationholds 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}eqnarrayputs too much space around the=and is discouraged; amsmath'salignreplaces it.Instead of\begin{eqnarray} a &=& b \end{eqnarray}Write\begin{align} a &= b \end{align}Nesting
alignin another display raises "Erroneous nesting of equation structures". Usealigned.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 ofa =& bWritea &= b
In Overleaf, MathJax and Word
Overleaf and pdfLaTeX
All environments come from amsmath. A blank line inside
alignis an error. Page breaks insidealignare off by default;\allowdisplaybreaksin the preamble permits them.MathJax and KaTeX
MathJax supports
align,align*,aligned,gather,multline,splitandalignat; numbering needs itstagsoption. KaTeX supportsalignedandgatheredanywhere andalignorgatherin 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 usemultlinefor a very long formula. - What is the difference between align and aligned?
alignis a standalone display environment with numbers.alignedgoes 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
alignedblock between\left\{and\right., or use\begin{cases} … \end{cases}for a simple brace on the left.
Related LaTeX reference
- Math Mode in LaTeXInline math with $…$ or \(…\), displayed math with \[…\], numbered equation environments, references and \text inside formulas.
- Piecewise Function in LaTeXThe cases environment: one line per piece, & before each condition, \text for words, dcases and rcases variants.
- Matrix in LaTeXpmatrix, bmatrix, vmatrix and friends: rows with \\, columns with &, plus 2x2, 3x3, augmented and n×n examples.
- LaTeX equation editorSymbol panel, live preview, and PNG, SVG, MathML or Word export.
- All LaTeX reference pagesSymbols, math structures and text formatting in one list.
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