Chapter 07 – Using Cross-References

Setting labels and references

\documentclass{book}
\begin{document}
\chapter{Statistics}
\section{Most used packages by LaTeX.org users}
\label{sec:packages}
The Top Five packages, used by LaTeX.org
members\footnote{according to the 2021 survey on
LaTeX.org\label{fn:project}}:
\begin{enumerate}
  \item graphicx\label{item:graphicx}
  \item babel
  \item amsmath\label{item:amsmath}
  \item geometry
  \item hyperref
\end{enumerate}
\chapter{Mathematics}
\emph{amsmath}, on position \ref{item:amsmath} of the top list
in section~\ref{sec:packages} on page~\pageref{sec:packages},
is indispensable to high-quality mathematical typesetting in
\LaTeX. \emph{graphicx}, on position \ref{item:graphicx},
is for including images. See also the footnote \ref{fn:project}
on page~\pageref{fn:project}.
\end{document}

Referring to a page

\documentclass{book}
\begin{document}
\chapter{Statistics}
\section{Introduction}
\newpage
\section{Most used packages by LaTeX.org users}
\label{sec:packages}
The Top Five packages, used by LaTeX.org
members\footnote{according to the 2021 survey on
LaTeX.org\label{fn:project}}:
\begin{enumerate}
  \item graphicx\label{item:graphicx}
  \item babel
  \item amsmath\label{item:amsmath}
  \item geometry
  \item hyperref
\end{enumerate}
\chapter{Mathematics}
\emph{amsmath}, on position \ref{item:amsmath} of the top list
in section~\ref{sec:packages} on page~\pageref{sec:packages},
is indispensable to high-quality mathematical typesetting in
\LaTeX. \emph{graphicx}, on position \ref{item:graphicx},
is for including images. See also the footnote \ref{fn:project}
on page~\pageref{fn:project}.
\end{document}

Producing intelligent page references

\documentclass{book}
\usepackage[nospace]{varioref}
\begin{document}
\chapter{Statistics}
\section{Most used packages by LaTeX.org users}
\label{sec:packages}
The Top Five packages, used by LaTeX.org
members\footnote{according to the 2021 survey on
LaTeX.org\label{fn:project}}:
\begin{enumerate}
  \item graphicx\label{item:graphicx}
  \item babel
  \item amsmath\label{item:amsmath}
  \item geometry
  \item hyperref
\end{enumerate}
\chapter{Mathematics}
\emph{amsmath}, on position \vref{item:amsmath} of the top list
in section~\vref{sec:packages}, is indispensable to high-quality
mathematical typesetting in \LaTeX. \emph{graphicx}, on position
\vref{item:graphicx}, is for including images. See also the
footnote \vref{fn:project}, that is, \vpageref{fn:project}.
\end{document}

varioref with figures:

\documentclass{article}
\usepackage{parskip}
\usepackage{graphicx}
\usepackage{varioref}
\usepackage{blindtext}
\begin{document}
\section{Figures}
\begin{figure}
\includegraphics{example-image}
\caption{An example figure}
\label{fig:example}
\end{figure}
\blindtext
\begin{figure}
\includegraphics{example-image}
\caption{Another example figure}
\label{fig:other}
\end{figure}
\newpage
Same reference code, different output:
\begin{verbatim}
See the \vpageref[above figure][figure]{fig:other} and
the \vpageref[above figure][figure]{fig:example}.
\end{verbatim}
See the \vpageref[above figure][figure]{fig:other} and
the \vpageref[above figure][figure]{fig:example}.
\end{document}

varioref with figures and ranges:

\documentclass{book}
\usepackage{parskip}
\usepackage{graphicx}
\usepackage[nospace]{varioref}
\usepackage{xcolor}
\usepackage{blindtext}
\begin{document}
\chapter{Figures}
\begin{figure}
\includegraphics{example-image}
\caption{An example figure}
\label{fig:example}
\end{figure}
\clearpage
\begin{figure}
\includegraphics{example-image}
\caption{Another example figure}
\label{fig:other}
\end{figure}
\clearpage
\begin{figure}
\includegraphics{example-image}
\caption{And another example figure}
\label{fig:last}
\end{figure}
\clearpage
See the figures \textcolor{red}{\vpagerefrange{fig:example}{fig:last}} and
figures \textcolor{blue}{\vrefrange{fig:example}{fig:last}}.
\end{document}

Using automatic reference names

\documentclass{book}
\usepackage{cleveref}
\crefname{enumi}{position}{positions}
\begin{document}
\chapter{Statistics}
\label{stats}
\section{Most used packages by LaTeX.org users}
\label{packages}
The Top Five packages, used by LaTeX.org
members\footnote{according to the 2021 survey on
LaTeX.org\label{project}}:
\begin{enumerate}
  \item graphicx\label{graphicx}
  \item babel
  \item amsmath\label{amsmath}
  \item geometry
  \item hyperref
\end{enumerate}
\chapter{Mathematics}
\label{maths}
\emph{amsmath}, on \cref{amsmath} of the top list in 
\cref{packages} of \cref{stats}, is indispensable to
high-quality mathematical typesetting in \LaTeX.
\emph{graphicx}, on \cref{graphicx}, is for including images.
See also the \cref{project} on \cpageref{project}.
\end{document}

cleveref and ranges:

\documentclass{book}
\usepackage{cleveref}
\crefname{enumi}{position}{positions}
\begin{document}
\chapter{Statistics}
\label{stats}
\section{Most used packages by LaTeX.org users}
\label{packages}
The Top Five packages, used by LaTeX.org
members\footnote{according to the 2021 survey on
LaTeX.org\label{project}}:
\begin{enumerate}
  \item graphicx\label{graphicx}
  \item babel
  \item amsmath\label{amsmath}
  \item geometry
  \item hyperref
\end{enumerate}
\chapter{Mathematics}
\label{maths}
See \crefrange{graphicx}{amsmath} and \cpagerefrange{stats}{maths}.
\end{document}