Sarmate.net Sarmate.net
Home Features Pricing Documentation Contact
Log in Sign up

Aligning equations in LaTeX

The amsmath package provides the align environment for aligning multiple equations at a common point (typically the = sign). Use & to mark the alignment point.

The align environment

LaTeX
\begin{align}
    x + y &= 5 \\
    2x - y &= 1
\end{align}

% Sans numérotation : align*
\begin{align*}
    (a + b)^2 &= a^2 + 2ab + b^2 \\
    (a - b)^2 &= a^2 - 2ab + b^2
\end{align*}

Multi-line calculation

To develop a calculation step by step, align on the = sign:

LaTeX
\begin{align*}
    f(x) &= (x+1)(x-2) \\
         &= x^2 - 2x + x - 2 \\
         &= x^2 - x - 2
\end{align*}

Centered equations with gather

If you simply want to center multiple equations without aligning them, use gather:

LaTeX
\begin{gather*}
    E = mc^2 \\
    F = ma \\
    PV = nRT
\end{gather*}
Warning Do not use eqnarray, which is obsolete. Always prefer align from the amsmath package, which handles spacing better.

Test your knowledge

3 questions to check what you have learned.

1

Which environment aligns several equations on the equals sign?

The align environment from the amsmath package is the recommended choice. eqnarray is obsolete and handles spacing poorly.

2

Which character marks the alignment point in align?

You place the ampersand & just before the alignment sign, e.g. &=, and end each line with \\.

3

Which environment centers several equations without aligning them to each other?

gather (and its unnumbered version gather*) centers each equation. To align them to each other, use align instead.

Try it in Sarmate

Edit, compile and download your LaTeX documents directly in your browser.

Open the editor