Tx · LaTeX & TikZ

How to Fix LaTeX Equation Numbering

Published By the 9to5Science editorial team

At a glance

  1. 1. Choose an environment

    Use equation for one number, align for numbered rows, and subequations for a group with lettered numbers.

  2. 2. Place labels correctly

    Give each numbered equation a unique label on its row, then refer to it with ref.

  3. 3. Check numbering rules

    Look for counter-reset commands, manual tags, and starred environments that suppress numbering.

LaTeX equation numbering depends on the math environment and the equation counter. A number that is missing, repeated, or formatted unexpectedly is often caused by using the wrong environment, placing a label on an unnumbered row, or changing the counter or number format elsewhere in the document.

The examples below use the amsmath package. They show how to number a single equation, number multiple lines, and create lettered subequations. If your specific output differs, compare your code with the relevant pattern and inspect commands that change numbering.

Choose the environment for the numbering you want

Use equation when a displayed expression should have one number. Use align when you want several aligned rows, each with its own number. Use subequations around a group when you want a shared parent number with lettered parts, such as (1a) and (1b).

The starred forms, such as equation* and align*, suppress automatic numbering. They are useful for unnumbered displays, but they will not produce numbers for \ref to retrieve.

For several lines that belong to one equation and need just one number, use aligned inside equation, or use split inside equation. Do not nest a complete align environment inside equation; both environments manage displayed equations and numbering.

A complete example with subequations

This example compiles with LaTeX and the amsmath package. It creates two lettered equation numbers and one following ordinary number.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{subequations}\label{eq:system}
\begin{align}
x + y &= 5, \label{eq:system-first}\\
x - y &= 1. \label{eq:system-second}
\end{align}
\end{subequations}

The system is given in \eqref{eq:system}. Its first equation is
\eqref{eq:system-first}, and its second is \eqref{eq:system-second}.

\begin{equation}\label{eq:next}
x = 3.
\end{equation}

The solution in \eqref{eq:next} follows by adding the two equations.

\end{document}

The system rows receive numbers such as (1a) and (1b); the following equation receives (2). The precise numbers depend on where these displays occur in your document. \label{eq:system} records the parent number, while the labels inside align record the individual lettered numbers. \eqref prints a reference with parentheses, while \ref prints the number without adding parentheses.

Each label must be unique. Put a row’s label on that row, usually after the equation content and before the row break \\. LaTeX writes reference information to auxiliary files, so references may show as ?? on the first run. Compile again to update them.

Numbering equations by section

If you want numbers to restart in each section, put this in the preamble, after loading amsmath:

\numberwithin{equation}{section}

In an article, equations in Section 2 would then typically be numbered (2.1), (2.2), and so on. Without this command, the equation counter normally continues through the document. If you use a class with chapters, you may prefer to number by chapter instead. Avoid adding a reset unless you want the numbering to restart; resetting the counter manually can cause duplicate numbers.

Common mistakes to check

  • Using a starred environment: align* and equation* do not generate numbers. Replace the starred form if you need automatic numbering.
  • Putting a label on an unnumbered row: In align, a row ending in \notag or \nonumber has no number to reference. Put the label on a numbered row instead.
  • Reusing a label: Every \label key should be distinct. A repeated key can make references point to the wrong equation.
  • Manually forcing a number: \tag{...} overrides the normal number for that display. Use it only when a custom number is intentional; it does not fix the equation counter’s sequence.
  • Resetting the counter unexpectedly: Search the preamble and document for \setcounter{equation}, \numberwithin, or other counter-changing commands.
  • Using eqnarray: Prefer align from amsmath. eqnarray has poor spacing around relation symbols and can make multi-line equation layouts harder to control.

If the problem persists, reduce the document to one equation that reproduces it, then add back packages and counter settings one at a time. This helps distinguish a numbering issue from a layout or package interaction.

References

  1. The amsmath package documentation

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.