> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/document-structure/03-cross-referencing-sections-equations-and-floats.md).

# 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:

```latex
\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.
```

![CrossReferencesEx1Overleaf.png](/files/Pa19vPivou1iNzzIVnXX)

The command `\label{ }` is used to set an identifier after the caption, that is later used in the command `\ref{ }` to set the reference.

[Open an example in Overleaf](https://www.overleaf.com/project/new/template/19401?id=65465598\&templateName=Cross+referencing+example\&latexEngine=\&texImage=texlive-full%3A2020.1\&mainFile=)

## Referencing sections and chapters

Below an example on how to reference a section

```latex
\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.
```

![CrossReferencesEx3Overleaf.png](/files/GvGtzhiZgLSMBDijlz1l)

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](/latex/document-structure/01-sections-and-chapters.md).

[Open an example in Overleaf](https://www.overleaf.com/project/new/template/19401?id=65465598\&templateName=Cross+referencing+example\&latexEngine=\&texImage=texlive-full%3A2020.1\&mainFile=)

## Referencing equations, figures and tables

At the [introduction](#introduction) an example of a image referenced was shown, below cross referencing equations is presented.

```latex
\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.
```

![CrossReferencesEx2Overleaf.png](/files/nTh9hSXSC3DESsz1lY0H)

For further and more flexible examples with labels and references see

* [Aligning equations with amsmath](/latex/mathematics/06-aligning-equations-with-amsmath.md)
* [Tables](/latex/figures-and-tables/01-tables.md)
* [Inserting Images](/latex/more-topics/27-inserting-images.md)

[Open an example in Overleaf](https://www.overleaf.com/project/new/template/19401?id=65465598\&templateName=Cross+referencing+example\&latexEngine=\&texImage=texlive-full%3A2020.1\&mainFile=)

## 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.

```latex
\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.
```

![CrossReferencesEx4Overleaf.png](/files/Ycoc3kqnC9gAuYk1asbC)

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.

[Open an example in Overleaf](https://www.overleaf.com/project/new/template/19401?id=65465598\&templateName=Cross+referencing+example\&latexEngine=\&texImage=texlive-full%3A2020.1\&mainFile=)

## 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:

* [Creating a document in LaTeX](/latex/latex-basics/01-learn-latex-in-30-minutes.md)
* [Mathematical expressions](/latex/mathematics/01-mathematical-expressions.md)
* [Aligning equations with amsmath](/latex/mathematics/06-aligning-equations-with-amsmath.md)
* [Inserting Images](/latex/more-topics/27-inserting-images.md)
* [Positioning images and tables](/latex/figures-and-tables/02-positioning-images-and-tables.md)
* [Indices](/latex/document-structure/04-indices.md)
* [Glossaries](/latex/document-structure/05-glossaries.md)
* [Table of contents](/latex/document-structure/02-table-of-contents.md)
* [Management in a large project](/latex/document-structure/07-management-in-a-large-project.md)
* [Multi-file LaTeX projects](/latex/document-structure/08-multi-file-latex-projects.md)
* [Hyperlinks](/latex/document-structure/09-hyperlinks.md)
* [Counters](/latex/formatting/10-counters.md)
* [The not so short introduction to LaTeX2ε](http://www.ctan.org/tex-archive/info/lshort/)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/document-structure/03-cross-referencing-sections-equations-and-floats.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
