If you need to insert cross-references to numbered elements in the document, (like equations, sections and figures) there are commands to automate it in LaTeX. This article explains how.
Contents |
Below you can see a simple example of images cross referenced:
\section{Introduction} \label{introduction} This is an introductory paragraph with some dummy text. This section will be later referenced. \begin{figure}[hbt!] \centering \includegraphics[width=0.3\linewidth]{lion-logo.png} \caption{This image will be referenced below} \label{fig:lion} \end{figure} You can reference images, for instance, figure \ref{fig:lion} shows the logo of the red lion logo.
The command \label{ }
is used to set an identifier that is later used in the command \ref{ }
to set the reference.
Below an example on how to reference a section
\section{Introduction} \label{introduction} This is an introductory paragraph with some dummy text. This section will be later referenced. \begin{figure}[h] \centering \includegraphics[width=0.3\linewidth]{lion-logo.png} \caption{This image will be referenced below} \label{fig:lion} \end{figure} You can reference images, for instance, the image \ref{fig:lion} shows the red lion logo. \section{Math references} \label{mathrefs} As mentioned in section \ref{introduction}, different elements can be referenced within a document
Again, the commands \label
and \ref
are used for references. The label can be set either right before or after the \section
statement. This also works on chapters, subsections and subsubsections. See Sections and chapters.
At the introduction an example of a image referenced was shown, below cross referencing equations is presented.
\section{Math references} \label{mathrefs} As mentioned in section \ref{introduction}, different elements can be referenced within a document \subsection{powers series} \label{subsection} \begin{equation} \label{eq:1} \sum_{i=0}^{\infty} a_i x^i \end{equation} The equation \ref{eq:1} is a typical power series.
For further and more flexible examples with labels and references see
Elements usually are referenced by a number assigned to them, but if you need to, you can insert the page where they appear.
\section{Math references} \label{mathrefs} As mentioned in section \ref{introduction}, different elements can be referenced within a document \subsection{powers series} \label{subsection} \begin{equation} \label{eq:1} \sum_{i=0}^{\infty} a_i x^i \end{equation} The equation \ref{eq:1} is a typical power series. \section{Last section} In the subsection \ref{subsection} at the page \pageref{eq:1} an example of a power series was presented.
The command \pageref
will insert the page where the element whose label is used appears. In the example above the equation 1. This command can be used with all other numbered elements mentioned in this article.
On Overleaf cross references work immediately, but for cross references to work properly in your local LaTeX distribution you must compile your document twice. There's also a command that can automatically do the job for all the references to work. For instance, if your document is saved as main.tex
latexmk -pdf main.tex
generates the file main.pdf with all cross-references working. To change the output format use -dvi
or -ps
.
For more information see: