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.

Try it in Sarmate

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

Open the editor