Cross referencing sections and equations
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.
Introduction
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.
Referencing sections and chapters
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.
Referencing equations, figures and tables
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
Referencing the page of an element
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.
Compiling documents with cross references
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
.
Further reading
For more information see:
Overleaf guides
- Creating a document in Overleaf
- Uploading a project
- Copying a project
- Creating a project from a template
- Including images in Overleaf
- Exporting your work from Overleaf
- Working offline in Overleaf
- Using Track Changes in Overleaf
- Using bibliographies in Overleaf
- Sharing your work with others
- Debugging Compilation timeout errors
- How-to guides
LaTeX Basics
- Creating your first LaTeX document
- Choosing a LaTeX Compiler
- Paragraphs and new lines
- Bold, italics and underlining
- Lists
- Errors
Mathematics
- Mathematical expressions
- Subscripts and superscripts
- Brackets and Parentheses
- Fractions and Binomials
- Aligning Equations
- Operators
- Spacing in math mode
- Integrals, sums and limits
- Display style in math mode
- List of Greek letters and math symbols
- Mathematical fonts
Figures and tables
- Inserting Images
- Tables
- Positioning Images and Tables
- Lists of Tables and Figures
- Drawing Diagrams Directly in LaTeX
- TikZ package
References and Citations
- Bibliography management in LaTeX
- Bibliography management with biblatex
- Biblatex bibliography styles
- Biblatex citation styles
- Bibliography management with natbib
- Natbib bibliography styles
- Natbib citation styles
- Bibliography management with bibtex
- Bibtex bibliography styles
Languages
- Multilingual typesetting on Overleaf using polyglossia and fontspec
- International language support
- Quotations and quotation marks
- Arabic
- Chinese
- French
- German
- Greek
- Italian
- Japanese
- Korean
- Portuguese
- Russian
- Spanish
Document structure
- Sections and chapters
- Table of contents
- Cross referencing sections and equations
- Indices
- Glossaries
- Nomenclatures
- Management in a large project
- Multi-file LaTeX projects
- Hyperlinks
Formatting
- Lengths in LaTeX
- Headers and footers
- Page numbering
- Paragraph formatting
- Line breaks and blank spaces
- Text alignment
- Page size and margins
- Single sided and double sided documents
- Multiple columns
- Counters
- Code listing
- Code Highlighting with minted
- Using colours in LaTeX
- Footnotes
- Margin notes
Fonts
Presentations
Commands
Field specific
- Theorems and proofs
- Chemistry formulae
- Feynman diagrams
- Molecular orbital diagrams
- Chess notation
- Knitting patterns
- CircuiTikz package
- Pgfplots package
- Typing exams in LaTeX
- Knitr
- Attribute Value Matrices
Class files
- Understanding packages and class files
- List of packages and class files
- Writing your own package
- Writing your own class
- Tips