Equation Numbering and Referencing in LaTeX: \label, \ref, \eqref
Quick answer
- Number an equation:
\begin{equation}...\end{equation}is numbered automatically;equation*(or\[ ... \]) is not. - Label it: put
\label{eq:energy}inside the environment. - Reference it:
\eqref{eq:energy}prints (1);\ref{eq:energy}prints 1;\cref{eq:energy}(cleveref) prints eq. (1). - Custom number:
\tag{A}replaces the number;\notagdrops it on one line of align. - Per-section numbers:
\numberwithin{equation}{section}in the preamble gives (1.1), (1.2), (2.1). - References show ??: compile twice; labels are resolved on the second run.
Use equation to number a display, put \label inside it, and reference the number with \eqref from amsmath. Choose align for separate numbered lines or splitinside equation for one number across several lines.
How to Number Equations in LaTeX: equation vs equation*
The equation environment produces a centered, numbered display. Its starred twin equation*, provided by amsmath, produces the same display without a number, and \[ ... \] is a shorthand for it. Load amsmath in every document that contains math; almost everything in this guide depends on it.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
E = mc^2
\end{equation}
\begin{equation*}
a^2 + b^2 = c^2
\end{equation*}
\[ F = ma \]
\end{document}The first display is “(1)”; the other two are unnumbered. The rule of thumb used by most journals: number an equation only if you refer to it somewhere. Avoid the plain TeX $$ ... $$ form; it has wrong spacing with amsmath and does not support \tag or \label properly.
How to Label and Reference Equations: \label, \ref and \eqref
Put \label inside the numbered environment. In align, place it on the intended row before the row break, not after the entire display. Three commands read it back:
\begin{equation}
\label{eq:energy}
E = mc^2
\end{equation}
Equation~\ref{eq:energy} ... % prints: Equation 1
Equation~(\ref{eq:energy}) ... % prints: Equation (1)
Equation~\eqref{eq:energy} ... % prints: Equation (1), with amsmath
on page~\pageref{eq:energy} % prints: on page 4\refprints the bare number. You add the parentheses yourself.\eqref(amsmath) prints the number with parentheses, in upright text even inside italics, exactly as the equation itself shows it. Use it for equations.- The tilde
~is a non-breaking space; it stops “Equation” and “(1)” from landing on different lines.
Labels are resolved on the next compilation run, so the first LaTeX pass after adding a new label can show ?? and the warning Label(s) may have changed. Rerun to get cross-references right. Compile twice, or use latexmk, which reruns as needed. An editor may already run LaTeX several times per build, so a single click can resolve the references. If they remain undefined, check the exact label spelling and whether the target actually has a number.
Pick a naming convention and keep it: eq: for equations, fig: for figures, tab: for tables, sec: for sections. The prefix is only a convention, but it makes \ref commands readable and prevents an equation and a figure from sharing a label by accident.
cleveref: \cref and \Cref
The cleveref package writes the word “equation” for you and handles lists and ranges. Load it after hyperref if you use that, and after amsmath:
\usepackage{amsmath}
\usepackage{hyperref}
\usepackage{cleveref}
See \cref{eq:energy}. % eq. (1)
See \Cref{eq:energy}. % Equation (1), at sentence start
See \cref{eq:energy,eq:momentum}. % eqs. (1) and (2)
See \crefrange{eq:first}{eq:last}. % eqs. (1) to (5)
% Change the wording once in the preamble
\crefname{equation}{Eq.}{Eqs.}
\Crefname{equation}{Equation}{Equations}With hyperref, every reference becomes a clickable link to the equation. See LaTeX Hyperlinks for the loading order and link colors.
Numbering Within Sections or Chapters
In article, equations are numbered 1, 2, 3 through the whole document. In book and report they are numbered per chapter: (2.1), (2.2). To number per section in any class, use \numberwithin from amsmath:
\usepackage{amsmath}
\numberwithin{equation}{section} % (1.1), (1.2), (2.1), ...
% In book/report, per section instead of per chapter:
\numberwithin{equation}{section} % (1.1.1), (1.1.2), ...
% Change only the printed form, keeping the counter global
\renewcommand{\theequation}{\Roman{equation}} % (I), (II), ...
\renewcommand{\theequation}{\thesection-\arabic{equation}} % (1-1), (1-2)\numberwithin both resets the equation counter at each section and prefixes the section number. The kernel command \counterwithin does the same without amsmath, and \counterwithout undoes it, which is how you get document-wide numbering in a book: \counterwithout{equation}{chapter}.
Numbers on the left
Equation numbers sit at the right margin by default. The leqno option moves them to the left, and fleqn left-aligns the equations themselves instead of centering them. Both are class options that amsmath also accepts:
\documentclass[leqno]{article} % numbers on the left
\documentclass[fleqn]{article} % equations flush left
\usepackage[leqno, fleqn]{amsmath} % same, as package optionsCustom Tags: \tag and \tag*
\tag replaces the automatic number with any text for that one equation. The equation counter is not advanced, so the next automatic number continues as if the tagged equation were not there. Avoid tags that duplicate automatic numbers: two equations called (1) are ambiguous even when their labels differ. Put a label on the tagged equation to reference the tag instead of typing it in the prose.\tag* prints the tag without parentheses:
\begin{equation}
\nabla \cdot \mathbf{E} = \frac{\rho}{\varepsilon_0} \tag{Gauss}
\end{equation}
\begin{equation}
x^2 + y^2 = r^2 \tag*{(circle)}
\end{equation}
% Tags work in the starred environments too
\begin{align*}
f(x) &= x^2 \tag{A} \\
g(x) &= 2x \tag{B} \label{eq:B}
\end{align*}
% Reuse an earlier number, e.g. when repeating an equation
\begin{equation}
E = mc^2 \tag{\ref{eq:energy}}
\end{equation}A tagged equation can carry a \label, and \eqref then prints the tag. For a primed repeat of equation (3), write \tag{\ref{eq:energy}$'$} to get (3′).
Suppressing Numbers: \nonumber, \notag and Starred Environments
There are three levels of control. For a whole display, use the starred environment (equation*, align*, gather*). For single lines in a multi-line environment, put \notag (or its older synonym \nonumber) before the line break:
\begin{align}
(a+b)^2 &= (a+b)(a+b) \notag \\
&= a^2 + ab + ba + b^2 \notag \\
&= a^2 + 2ab + b^2 \label{eq:binomial}
\end{align}Only the last line gets a number, (1), and the label refers to it. This is the most common pattern in derivations: intermediate steps unnumbered, the result numbered.
Multi-Line Equations: align, split, multline and gather
amsmath offers several environments for displays with more than one line. The choice depends on two things: whether the lines should be aligned on a symbol, and whether you want one number for the whole block or one per line.
| Environment | Alignment | Numbering | Typical use |
|---|---|---|---|
align / align* | At each & | Every line (or none) | Derivations, systems of equations |
split (inside equation) | At & | One number, centered on the block | One long equation broken into aligned lines |
multline / multline* | First line left, last line right | One number on the last line | One long equation with no natural alignment point |
gather / gather* | Each line centered | Every line (or none) | Several unrelated equations in one display |
aligned, gathered | Like align/gather | Inherit from the enclosing equation | Aligned block that is part of a larger equation |
cases | Left-aligned columns with a brace | Inherits | Piecewise definitions |
flalign | Spread to full width | Every line | Equation on the left, condition on the right |
align: a number on every line
\begin{align}
x + y &= 10 \label{eq:sum} \\
x - y &= 2 \label{eq:diff}
\end{align}
Adding \eqref{eq:sum} and \eqref{eq:diff} gives $x = 6$.The & marks the alignment point (usually just before =), and \\ ends each line except the last. A second pair of columns can be added with more ampersands: a &= b & c &= d sets two equations side by side.
split: one number for a broken equation
\begin{equation}
\label{eq:long}
\begin{split}
(a + b)^4 &= a^4 + 4a^3b + 6a^2b^2 \\
&\quad + 4ab^3 + b^4
\end{split}
\end{equation}The number is centered vertically on the whole block, and the label goes on the outer equation. The \quad at the start of the continuation line is the conventional indent that shows the line is a continuation, not a new equation.
multline: long equations without an alignment point
\begin{multline}
\label{eq:series}
1 + \frac{1}{2} + \frac{1}{3} + \frac{1}{4} + \frac{1}{5} + \frac{1}{6}
+ \frac{1}{7} + \frac{1}{8} \\
+ \frac{1}{9} + \frac{1}{10} + \dots + \frac{1}{n} = H_n
\end{multline}gather: centered lines, each numbered
\begin{gather}
a = b + c \\
d + e + f + g = h \notag \\
x = y
\end{gather}aligned and cases inside equation
aligned and gathered are building blocks, not full displays: they take no number of their own and can sit next to other material in an equation. cases is the same idea with a left brace:
\begin{equation}
\label{eq:abs}
|x| =
\begin{cases}
x & \text{if } x \geq 0 \\
-x & \text{if } x < 0
\end{cases}
\end{equation}
\begin{equation}
\left.
\begin{aligned}
u &= x + y \\
v &= x - y
\end{aligned}
\right\} \quad \text{(change of variables)}
\end{equation}Never nest align inside equation: both are top-level displays and amsmath stops with erroneous nesting of equation structures. Use split or aligned inside, and align on its own.
For text between rows of align, use \intertext.\allowdisplaybreaks permits page breaks between rows of environments such as align and gather, but not inside the unbreakablesplit and aligned building blocks. A long derivation that must span pages should not be wrapped in one equation.
Subequations: (1a), (1b), (1c)
Wrap any numbered environment in subequations and the lines are numbered with the parent number plus a letter. A label on the wrapper refers to the group:
\begin{subequations}
\label{eq:maxwell}
\begin{align}
\nabla \cdot \mathbf{E} &= \frac{\rho}{\varepsilon_0} \label{eq:gauss} \\
\nabla \cdot \mathbf{B} &= 0 \label{eq:nomonopole} \\
\nabla \times \mathbf{E} &= -\frac{\partial \mathbf{B}}{\partial t} \label{eq:faraday}
\end{align}
\end{subequations}
Maxwell's equations \eqref{eq:maxwell} ... % (1)
Gauss's law \eqref{eq:gauss} ... % (1a)The letter style comes from \theequation inside the group; for roman numerals or another separator, redefine it right after \begin{subequations}: \renewcommand{\theequation}{\theparentequation.\roman{equation}} gives (1.i), (1.ii).
Common Errors
| Message or symptom | Cause | Fix |
|---|---|---|
| Missing $ inserted | Math-only syntax (_, ^, \frac, Greek letters) used outside math, or an unclosed $ | Wrap the expression in $...$ or a display environment; check for a missing \end{equation} |
\\ inside equation does nothing or errors | equation is single-line | Use split, multline or align |
| Label(s) may have changed. Rerun to get cross-references right | Labels are resolved on the next run | Compile again (twice after adding labels), or use latexmk |
| Undefined control sequence \eqref | amsmath not loaded | \usepackage{amsmath} |
| LaTeX Warning: Reference `eq:x' on page 1 undefined | The label has not been written to the .aux file yet, or it does not exist | Compile a second time; if the warning stays, the label is misspelled or missing |
| Reference shows ?? | Label misspelled, not yet compiled twice, or placed outside the numbered environment | Check the spelling; keep \label inside the environment |
| Erroneous nesting of equation structures | align or gather inside equation | Use split, aligned or gathered inside; align on its own |
| Multiple \label's: label 'eq:x' will be lost | Two \label commands on the same numbered line | Keep one label per number |
| \tag not allowed here or tag ignored | \tag inside $$...$$, or in an environment that cannot number (aligned, split) | Use \[ \] or equation; put the tag on the outer environment |
Numbers like (0.1) in an article | \numberwithin used but the equation comes before the first \section | Move the equation after a section heading, or drop \numberwithin |
Complete Example
\documentclass{article}
\usepackage{amsmath}
\usepackage[hidelinks]{hyperref}
\usepackage{cleveref}
\numberwithin{equation}{section}
\crefname{equation}{Eq.}{Eqs.}
\Crefname{equation}{Equation}{Equations}
\begin{document}
\section{Kinematics}
A body with constant acceleration satisfies
\begin{equation}
\label{eq:velocity}
v = v_0 + at
\end{equation}
and
\begin{equation}
\label{eq:position}
x = x_0 + v_0 t + \tfrac{1}{2} a t^2 .
\end{equation}
Eliminating $t$ between \cref{eq:velocity,eq:position}:
\begin{align}
t &= \frac{v - v_0}{a} \notag \\
x - x_0 &= v_0 \frac{v - v_0}{a} + \frac{(v - v_0)^2}{2a} \notag \\
v^2 &= v_0^2 + 2a(x - x_0). \label{eq:torricelli}
\end{align}
\Cref{eq:torricelli} contains no time variable.
\section{Field equations}
\begin{subequations}
\label{eq:maxwell}
\begin{align}
\nabla \cdot \mathbf{E} &= \rho / \varepsilon_0 \label{eq:gauss} \\
\nabla \cdot \mathbf{B} &= 0 \label{eq:nomono}
\end{align}
\end{subequations}
Together, \eqref{eq:maxwell} are two of Maxwell's equations;
\eqref{eq:gauss} alone is Gauss's law.
A long identity with a single number:
\begin{equation}
\label{eq:binom}
\begin{split}
(a+b)^4 &= a^4 + 4a^3 b + 6a^2 b^2 \\
&\quad + 4ab^3 + b^4 .
\end{split}
\end{equation}
A named equation instead of a number:
\begin{equation}
e^{i\pi} + 1 = 0 \tag{Euler}
\end{equation}
The piecewise function
\begin{equation*}
|x| =
\begin{cases}
x & \text{if } x \ge 0, \\
-x & \text{otherwise}
\end{cases}
\end{equation*}
is not numbered because it is never referenced; \cref{eq:binom} is.
\end{document}Compile twice. The equations are numbered (1.1), (1.2), (1.3), (2.1a), (2.1b), (2.2) and (Euler), and every \cref and \eqref resolves to the right one.
Frequently Asked Questions
How do you number equations in LaTeX?
Use the equation environment: \begin{equation} E = mc^2 \end{equation} is numbered (1), (2), (3) automatically. Use equation* or \[ ... \] for an unnumbered display, and align for several numbered lines. Add \numberwithin{equation}{section} to the preamble to number per section, as (1.1), (1.2).
How do you reference an equation in LaTeX?
Put \label{eq:name} inside the equation and write \eqref{eq:name} where you want the number. \eqref comes from amsmath and prints the number in parentheses, (1). \ref{eq:name} prints the bare number, and \cref{eq:name} from cleveref adds the word, eq. (1). Compile twice so the numbers resolve.
What is the difference between \ref and \eqref?
\ref prints only the number, so you write the parentheses yourself: (\ref{eq:x}). \eqref prints the number with parentheses, upright even inside italic text, exactly as it appears next to the equation. Use \eqref for equations and \ref for sections, figures and tables.
Why does my equation reference show ?? or say Reference undefined?
LaTeX writes labels to the .aux file on one run and reads them on the next, so the first LaTeX pass after adding a new label can show ??. Compile a second time. If the warning stays, the label name is misspelled, or \label is outside the numbered environment, or it is on a line suppressed with \notag.
How do I remove the number from one equation?
Use the starred environment, equation* or align*, for a whole display. Inside a numbered align, put \notag (or \nonumber) before the \\ of each line that should not be numbered. \tag{text} replaces the number with your own label instead.
How do I number equations as (1a), (1b)?
Wrap the equations in the subequations environment from amsmath: \begin{subequations} \begin{align} ... \end{align} \end{subequations}. Each line gets the parent number plus a letter, and a \label placed directly inside subequations refers to the whole group.
Next Steps
Numbering under control? Continue with the rest of the math toolkit:
- Mathematical Expressions – Fractions, roots, operators and the amsmath environments in detail
- Theorems, Lemmas and Proofs – amsthm, \newtheorem and the QED symbol, with the same \label/\cref workflow
- Matrices in LaTeX – pmatrix, bmatrix and augmented matrices inside numbered equations
- LaTeX Hyperlinks – Make equation references clickable with hyperref
Free LaTeX Tools
- Math to LaTeX Converter – Turn handwritten or typed math into LaTeX
- LaTeX Preview – Check equation numbering with a live PDF preview
- LaTeX Symbols Reference – Browse math operators and special characters
Related Articles
Angle Brackets ⟨ ⟩: Symbol, Copy and Paste, and LaTeX
Compile LaTeX from Claude Code or Cursor with the Octree MCP Server
Diameter Symbol (⌀): Meaning, ⌀ vs Ø, and How to Type It on Windows, Mac, Word, LaTeX
LaTeX on iPad: How to Write and Compile LaTeX on a Tablet
Fix equation errors faster with AI
Open the complete example in Octree and ask AI chat about a numbering error. Compile the result, then check the printed numbers and clickable references.
Try Octree Free →