Figure caption and label in LaTeX (caption, label, ref)

\caption{text} inside a figure environment prints "Figure 1: text" and numbers the figure. A \label after it names the figure, and \ref prints its number in the text.

Preamble

The snippets on this page need these lines before \begin{document}:

\usepackage{graphicx}
\usepackage{caption}

Add a caption and refer to the figure

The caption stands below the image when \caption follows \includegraphics. The label name is free; the prefix fig: keeps figures apart from tables and sections. Compile twice so that \ref shows the number.

\begin{figure}
\centering
\includegraphics[width=0.5\textwidth]{image.png}
\caption{The measurement setup}
\label{fig:setup}
\end{figure}

Figure~\ref{fig:setup} shows the setup.
Result
The compiled example

Give the list of figures a shorter text

The optional argument of \caption is the text for \listoffigures. Use it when the caption is long or contains a citation that should not appear in the list.

\listoffigures

\begin{figure}
\centering
\includegraphics[width=0.5\textwidth]{image.png}
\caption[Measurement setup]{The measurement setup with the laser on the left
and the detector on the right}
\end{figure}
Result
The compiled example

Change the look and the name

The caption package formats all captions with \captionsetup. font=small reduces the font size, labelfont=bf sets "Figure 1" in bold, and name=Fig. in the settings for figure replaces the word "Figure".

This goes into the preamble.

\captionsetup{font=small, labelfont=bf}
\captionsetup[figure]{name=Fig.}

Open in the editor

Caption without a figure environment

\captionof{figure}{text} from the caption package numbers an image that does not float, for example in a minipage or a center environment. \caption*{text} inside a figure prints the text without "Figure" and a number.

\begin{center}
\includegraphics[width=0.5\textwidth]{image.png}
\captionof{figure}{The measurement setup}
\label{fig:setup-here}
\end{center}
Result
The compiled example

Pitfalls

Compiled with pdfLaTeX from TeX Live 2023.

Related pages