Number equations in LaTeX (equation, tag, notag)
The equation environment numbers a formula automatically; \label and \eqref refer to it. equation* or \[...\] sets a formula without a number.
Preamble
The snippets on this page need these lines before \begin{document}:
\usepackage{amsmath}Number an equation and refer to it
\label{name} inside the environment stores the number. \eqref{name} from amsmath prints it in parentheses, \ref{name} prints the bare number. The number shows up after the second compile run.
\begin{equation}
E = mc^2 \label{eq:energy}
\end{equation}
Equation~\eqref{eq:energy} relates mass and energy.Leave out the number
equation* from amsmath and \[...\] set a formula without a number. In an environment with several lines such as align, \notag removes the number of one line.
\begin{equation*}
a^2 + b^2 = c^2
\end{equation*}
\begin{align}
x &= y + z \notag \\
y &= 2z
\end{align}Number equations per section
\numberwithin{equation}{section} in the preamble puts the section number in front and restarts the count in every section: (1.1), (1.2), (2.1). The classes report and book already number equations per chapter.
Complete document:
\documentclass{article}
\usepackage{amsmath}
\numberwithin{equation}{section}
\begin{document}
\section{Results}
\begin{equation}
a = b
\end{equation}
\end{document}Use your own label instead of a number
\tag{text} replaces the number with your own text in parentheses and does not use up an equation number; \tag*{text} leaves out the parentheses. The argument is normal text, so a symbol goes between $...$.
\begin{equation}
x^2 \ge 0 \tag{$*$}
\end{equation}
\[
a + b = b + a \tag{commutativity}
\]Sub-numbers: 1a, 1b
Inside subequations all equations share one number and get the letters a, b, c. A \label right after \begin{subequations} refers to the shared number.
\begin{subequations}
\begin{align}
x + y &= 3 \\
x - y &= 1
\end{align}
\end{subequations}Pitfalls
- A reference that prints "??" needs one more compile run. If it stays, the name in
\eqrefdoes not match any\label: see Reference `sec:methods' on page 1 undefined. - In
align, put each\labelbefore the\\of its line. Two labels with the same name produce the warning Label `sec:intro' multiply defined. - The class option
leqnomoves the numbers to the left margin:\documentclass[leqno]{article}. The optionfleqnsets the formulas flush left instead of centred.
Compiled with pdfLaTeX from TeX Live 2023.
Related pages
- Package
amsmath - How-to Align equations in LaTeX
- How-to Cross-references in LaTeX
- Error Reference `sec:methods' on page 1 undefined
- Error Label `sec:intro' multiply defined