The Nightmare Scenario
You're finalizing your thesis. You add a figure to Chapter 2. Suddenly, every figure reference after it is wrong. "See Figure 3" now points to Figure 4. You manually renumber everything.
Then your advisor says to move Figure 7 earlier in the document.
This nightmare is entirely preventable. LaTeX's cross-referencing system means you never type "Figure 3" manually. You label once, reference by name, and LaTeX handles all the numbering. Add figures, move sections, reorganize chapters—every reference updates automatically.
Here's how to set it up right. (For a tool that handles this automatically as you write, try our LaTeX editor with real-time preview.)
The Basic System
Labels
Attach labels to anything you want to reference:
\section{Introduction}
\label{sec:introduction}
\begin{figure}
\includegraphics{...}
\caption{Results overview}
\label{fig:results}
\end{figure}
\begin{equation}
E = mc^2
\label{eq:einstein}
\end{equation}
\begin{table}
...
\caption{Summary statistics}
\label{tab:summary}
\end{table}References
Reference labels anywhere in your document:
As shown in Section \ref{sec:introduction}...
Figure \ref{fig:results} demonstrates...
From Equation \ref{eq:einstein}, we derive...
Table \ref{tab:summary} presents...Compile Twice
Cross-references require two compilations:
- First pass: LaTeX records labels
- Second pass: LaTeX fills in references
If you see ??, compile again.
Naming Conventions
Prefix System
Use consistent prefixes for different element types:
| Type | Prefix | Example |
|------|--------|---------|
| Section | sec: | \label{sec:methods} |
| Figure | fig: | \label{fig:diagram} |
| Table | tab: | \label{tab:results} |
| Equation | eq: | \label{eq:derivative} |
| Chapter | ch: | \label{ch:introduction} |
| Appendix | app: | \label{app:proofs} |
| Theorem | thm: | \label{thm:main} |
| Lemma | lem: | \label{lem:helper} |
| Definition | def: | \label{def:concept} |
This makes labels self-documenting and prevents conflicts.
Descriptive Names
Choose meaningful names:
% Good
\label{fig:experimental-setup}
\label{tab:participant-demographics}
\label{eq:bayesian-posterior}
% Less helpful
\label{fig:figure1}
\label{tab:table}
\label{eq:eq2}Descriptive names help when your document grows large.
The cleveref Package
The cleveref package automates reference formatting:
\usepackage{cleveref}
% Automatic type detection
\cref{sec:methods} % section 3
\cref{fig:results} % figure 2
\cref{eq:einstein} % equation 1
% Capitalized at sentence start
\Cref{sec:methods} % Section 3
% Multiple references
\cref{fig:a,fig:b,fig:c} % figures 1, 2, and 3
\cref{eq:1,eq:2} % equations 1 and 2Configuring cleveref
\usepackage{cleveref}
% Customize names
\crefname{equation}{Eq.}{Eqs.}
\crefname{figure}{Fig.}{Figs.}
\crefname{table}{Tab.}{Tabs.}
\crefname{section}{Sec.}{Secs.}
% Or full names
\crefname{equation}{Equation}{Equations}Range References
\crefrange{eq:first}{eq:last}
% Output: equations 1 to 5
\crefrange{fig:a}{fig:d}
% Output: figures 3 to 6Hyperlinks with hyperref
Basic Setup
\usepackage{hyperref}
% References become clickable
See Section \ref{sec:methods} % Clicking jumps to that sectionConfiguration
\usepackage{hyperref}
\hypersetup{
colorlinks=true,
linkcolor=blue,
citecolor=blue,
urlcolor=blue,
pdftitle={Your Paper Title},
pdfauthor={Your Name}
}Link Styles
% Colored links (screen-friendly)
\hypersetup{colorlinks=true, linkcolor=blue}
% Boxed links (don't print)
\hypersetup{colorlinks=false}
% No visible links (professional print)
\hypersetup{hidelinks}For submissions, journals often prefer hidelinks or black links.
Manual Hyperlinks
% URL links
\url{https://example.com}
\href{https://example.com}{Click here}
% Internal links
\hyperref[sec:methods]{see the methods section}Page References
\pageref
Reference page numbers:
See Figure \ref{fig:results} on page \pageref{fig:results}.\vref (varioref)
Smart page references:
\usepackage{varioref}
\vref{fig:results}
% Outputs contextually:
% "figure 3" (same page)
% "figure 3 on the facing page" (adjacent page)
% "figure 3 on page 42" (distant page)Equation References
Standard References
\begin{equation}
a^2 + b^2 = c^2
\label{eq:pythagoras}
\end{equation}
From Equation \ref{eq:pythagoras}...
% Output: From Equation (1)...eqref for Parentheses
\usepackage{amsmath}
From \eqref{eq:pythagoras}...
% Output: From (1)...Subequations
\begin{subequations}
\label{eq:maxwell}
\begin{align}
\nabla \cdot \mathbf{E} &= \frac{\rho}{\epsilon_0} \label{eq:gauss} \\
\nabla \cdot \mathbf{B} &= 0 \label{eq:divb}
\end{align}
\end{subequations}
Maxwell's equations \eqref{eq:maxwell} include Gauss's law \eqref{eq:gauss}...
% Output: Maxwell's equations (1) include Gauss's law (1a)...Figure and Table References
Label Placement
Labels must come after \caption:
% Correct
\begin{figure}
\includegraphics{...}
\caption{Description}
\label{fig:correct} % After caption
\end{figure}
% Incorrect (label references the section, not the figure)
\begin{figure}
\label{fig:wrong} % Before caption - WRONG
\includegraphics{...}
\caption{Description}
\end{figure}Subfigures
\usepackage{subcaption}
\begin{figure}
\begin{subfigure}[b]{0.45\textwidth}
\includegraphics{a}
\caption{First part}
\label{fig:sub-a}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.45\textwidth}
\includegraphics{b}
\caption{Second part}
\label{fig:sub-b}
\end{subfigure}
\caption{Overall caption}
\label{fig:overall}
\end{figure}
\cref{fig:overall} shows... \cref{fig:sub-a} specifically...
% Output: Figure 1 shows... Figure 1a specifically...Bibliography References
Basic Citations
\cite{smith2020} % [1] or (Smith, 2020)
\cite{a,b,c} % [1,2,3] or (A; B; C)With natbib
\usepackage{natbib}
\citet{smith2020} % Smith (2020)
\citep{smith2020} % (Smith, 2020)
\citet*{smith2020} % Full author list
\citep[p.~5]{smith} % (Smith, 2020, p. 5)With biblatex
\usepackage{biblatex}
\textcite{smith2020} % Smith (2020)
\parencite{smith2020} % (Smith, 2020)
\autocite{smith2020} % Style-dependentTroubleshooting
Undefined References
LaTeX Warning: Reference `fig:results' on page 2 undefined.Causes:
- Typo in label or reference
- Forgot to add label
- Need to compile again
Fix: Check spelling, add missing label, compile twice.
Multiply-Defined Labels
LaTeX Warning: Label `fig:results' multiply defined.Cause: Same label used twice.
Fix: Rename one of the labels.
Wrong Reference Type
% Referencing a figure with \eqref
\eqref{fig:results} % Wrong: shows (3) instead of Figure 3Fix: Use \ref or \cref for non-equations.
hyperref Conflicts
hyperref should usually be loaded last:
\usepackage{...}
\usepackage{...}
\usepackage{hyperref} % Load last
\usepackage{cleveref} % Exception: cleveref after hyperrefBest Practices
1. Label Everything
Even if you don't reference it now, you might later:
\section{Background}
\label{sec:background} % Always add labels2. Use Consistent Prefixes
Establish conventions at project start and follow them.
3. Compile Twice Before Checking
References need two passes. Always compile twice before panicking.
4. Check References Before Submission
Search your document for ?? to find undefined references.
5. Keep Labels Stable
Changing a label requires updating all references to it. Choose descriptive, stable names.
Quick Reference
Essential Commands
% Labeling
\label{prefix:name}
% Basic references
\ref{label} % Just the number
\pageref{label} % Page number
% With amsmath
\eqref{label} % Equation in parentheses
% With cleveref
\cref{label} % Type and number
\Cref{label} % Capitalized
\crefrange{a}{b} % Range
% With hyperref
\hyperref[label]{text} % Custom link text
\url{https://...} % URL
\href{url}{text} % Linked textLoad Order
\usepackage{amsmath}
\usepackage{...}
\usepackage{varioref} % If using
\usepackage{hyperref} % Near last
\usepackage{cleveref} % After hyperrefConclusion
Cross-referencing transforms document maintenance:
- Label everything with consistent prefixes
- Use cleveref for smart references
- Enable hyperlinks for navigation
- Compile twice for accurate references
Once you embrace cross-referencing, manual numbering feels primitive. Your documents become more maintainable, more flexible, and more professional.
Never type "Figure 3" again.