Typevia
Mathematical Typesetting

Introduction to Equation Alignment

In mathematical typesetting, clarity is just as important as correctness. When you have a series of mathematical steps or a system of equations, simply typing them one after another can result in a messy, hard-to-read document.

Equation alignment is the process of organizing multiple lines of math so that specific elements—usually the equals signs—line up vertically. This not only makes your work look professional but also helps the reader follow the logical flow of your derivation.

To unlock the best alignment features in LaTeX, you must include the amsmath package in your document preamble:

\usepackage{amsmath}

This package is the industry standard for mathematical typesetting and provides the environments we will discuss in this guide.


The Workhorse: The align Environment

The most common and versatile tool for lining up equations is the align environment. It allows you to create multiple lines of math where specific points are anchored together.

The Basic Syntax

The align environment uses two special characters to control the layout:

  1. The Ampersand (&): This is the alignment anchor. LaTeX will vertically align every character that immediately follows this symbol.
  2. The Double Backslash (\\): This indicates a line break. You do not need this on the final line.

Example: A Simple Derivation

In most cases, you want to align the equals signs in a step-by-step calculation.

\begin{align}
    f(x) &= (x + 3)^2 \\
         &= x^2 + 6x + 9
\end{align}

Note: Notice how the & is placed directly before the = sign. This tells LaTeX: "Make sure all these equals signs stay in a straight vertical line."


Numbering and Suppressing Numbers

By default, the align environment automatically assigns a number to every single line. This is helpful for referencing specific steps later in your text, but it can clutter your document if every line is numbered.

Using align* for Unnumbered Equations

If you don't want any numbers at all, use the "starred" version of the environment:

\begin{align*}
    2x + 5 &= 15 \\
    2x &= 10 \\
    x &= 5
\end{align*}

Selective Numbering

If you want to number the entire block as one or only number specific lines, you have two options:

  1. \nonumber or \notag: Place this command before the line break (\\) to hide the number for that specific line.
  2. The aligned environment: This is a "sub-environment" used inside a standard equation environment to treat multiple lines as a single numbered unit.
\begin{equation}
\begin{aligned}
    a &= b + c \\
    d &= e + f
\end{aligned}
\end{equation}

In the example above, the two lines are aligned at the equals sign, but they will share a single equation number centered between them.


Multiple Columns of Equations

Sometimes you need to display two or more sets of equations side-by-side to save space or show parallel steps. The align environment handles this by using additional ampersands.

In a multi-column align block, the ampersands work in pairs:

  • The first & is the alignment point for the first column.
  • The second & acts as a separator between the columns.
  • The third & is the alignment point for the second column, and so on.

Example: Parallel Equations

\begin{align*}
    x &= 1  &  y &= 2  &  z &= 3 \\
    x+a &= 1+a  &  y+b &= 2+b  &  z+c &= 3+c
\end{align*}

Best Practice: When using multiple columns, ensure there is enough horizontal space between them. LaTeX adds a bit of space automatically, but if it looks cramped, you can add manual spacing commands like \quad or \qquad next to the separator ampersand.


When Alignment Isn't Needed: The gather Environment

There are times when you want to group several equations together but they don't share a logical alignment point (like an equals sign). In this case, using align would look forced and awkward.

The gather environment is used to display multiple equations, each centered on its own line, without aligning them to any specific character.

\begin{gather*}
    2x + 3y = 10 \\
    x^2 + y^2 + z^2 = 1 \\
    a + b = c
\end{gather*}

Like align, gather has a starred version (gather*) for unnumbered equations.


Best Practices and Common Pitfalls

To create the most readable and professional-looking math, keep these tips in mind:

1. Placement of the Ampersand

Always place the & before the relation symbol (like =, <, >).

  • Correct: &=
  • Incorrect: =& Placing it before ensures that the spacing around the operator remains consistent with standard LaTeX math spacing.

2. Avoid Over-alignment

Don't feel the need to align every single line in a long document to the same point. Only align equations that are logically related, such as steps in a single derivation or a system of equations.

3. Long Equations (Line Breaking)

If a single equation is too long to fit on one line, you can use the split environment inside an equation environment. This allows you to break the equation and align the second line at a custom point (usually after the equals sign or an operator).

\begin{equation}
\begin{split}
    L = &ax^2 + bx + c \\
        &+ dy^2 + ey + f
\end{split}
\end{equation}

4. Common Errors

  • Forgetting the amsmath package: If you get an "Unknown environment" error, check your preamble.
  • Missing \\: If your equations are all smashed onto one line, you likely forgot the double backslash at the end of a row.
  • Extra \\ on the last line: Adding a line break on the very last line of an align environment can sometimes create an unwanted empty numbered line.

5. Adding Text Inside Alignment

If you want to add a brief explanation next to an equation within the align block, use the \text{...} command.

\begin{align*}
    x^2 - 4 &= 0 \\
    (x-2)(x+2) &= 0 && \text{by factoring} \\
    x &= \pm 2 && \text{final result}
\end{align*}

By following these structures, your LaTeX documents will transform from simple text files into beautifully typeset mathematical manuscripts. Practice by taking a multi-step problem from a textbook and trying to replicate its alignment in LaTeX!