Referencing Figures
Open an example of cross-referencing figures in Overleaf
In LaTeX, we can label entities that are numbered (sections, formulas, etc), and then use that label to refer to them elsewhere, and the same commands apply to the figure environment as well (they are numbered).
Basics of Labels and Referencing
\label{marker}
The marker can be seen as a name that we give to the object that we want to reference. It's important to add \label
after a numbered element e.g. \section
, \subsection
, \caption
etc, otherwise the label won't "latch on" to the correct number or counter.
\ref{marker}
This prints the number assigned to the object labeled by marker.
\pageref{marker}
This prints the number of the page where the object labeled by marker appears.
Compiling a LaTeX document with labels and references
The marker used to label objects is not shown anywhere in the document, and references to it are replaced with the appropriate numbers. If we reference a non-existent marker, LaTeX will compile successfully but with a warning about undefined references. The reference to the unknown marker will be replaced by ??.
In the example from Overleaf included above, you can see that we could successfully add reference to figures included in the document later. To make it possible, LaTeX has to be run twice - the first run compiles and stores all labels and their positions, and in the second run all the references are replaced with the appropriate numbers. Thus, we have to compile our document twice to see the correct output.
Using meaningful names to refer to figures
Since we can use any string as a label, it's a common practice to add a few letters to the label (as prefix) to indicate what is being labeled. This becomes important when a lot of different types of objects are referenced in a document, as it might be useful to remember the kind of object a label refers to it. Besides, it also makes it possible to reference different kind of objects using a common string.
For example, if a document contains
- a section on population of nations,
- a table containing the population numbers, and
- a figure containing a bar chart of the population sizes,
it might be convenient to refer to all of them using variants of population. This can be accomplished by using the labels
- sec:population for the section,
- tab:population for the table, and
- fig:population for the figure.
The following is an example for figures -
\begin{figure}[h!]
\includegraphics[scale=1.7]{birds.jpg}
\caption{The birds}
\label{fig:birds}
\end{figure}
Again, note that \label
is given after \caption
.
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