Cross referencing sections, equations and floats
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 figures cross referenced by their figure caption numbers:
\section{Introduction} \label{introduction}
This is an introductory paragraph with some dummy text. This section will be referenced later.
\begin{figure}[h]
\centering
\includegraphics[width=0.3\linewidth]{overleaf-logo}
\caption{This image will be referenced below.}
\label{fig:leaf}
\end{figure}
You can reference images; for instance, Figure \ref{fig:leaf} shows the \textit{Overleaf} logo.
The command \label{ }
is used to set an identifier after the caption, 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 referenced later.
\begin{figure}[h]
\centering
\includegraphics[width=0.3\linewidth]{overleaf-logo}
\caption{This image will be referenced below.}
\label{fig:leaf}
\end{figure}
You can reference images; for instance, Figure \ref{fig:leaf} shows the \textit{Overleaf} logo.
\vspace{0.5cm}
\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 is set after the \section
statement, i.e. the \label
command should be added after the counter number for the section has been generated. 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}
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}
Equation \ref{eq:1} is a typical power series.
\vspace{0.5cm}
%\Blindtext
\section{Last section}
In subsection \ref{subsection} on 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
- Using the Overleaf project menu
- 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
- Using the History feature
- Debugging Compilation timeout errors
- How-to guides
- Guide to Overleaf’s premium features
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
- Matrices
- 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
- Using the Symbol Palette in Overleaf
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 with bibtex
- Bibliography management with natbib
- Bibliography management with biblatex
- Bibtex bibliography styles
- Natbib bibliography styles
- Natbib citation styles
- Biblatex bibliography styles
- Biblatex citation styles
Languages
- Multilingual typesetting on Overleaf using polyglossia and fontspec
- Multilingual typesetting on Overleaf using babel 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, equations and floats
- 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
- Typesetting 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