Tx · LaTeX & TikZ

How to Show Figure Numbers in Beamer

Published By the 9to5Science editorial team

At a glance

  1. 1. Enable numbered captions

    Add \setbeamertemplate{caption}[numbered] to the preamble, before \begin{document}.

  2. 2. Add a caption

    Put \caption{...} inside the figure environment; the environment alone does not print a caption.

  3. 3. Label after caption

    Place \label{...} after \caption if you want to refer to the figure number.

Beamer does not show figure numbers in captions by default. To display them, switch to its numbered caption template in the preamble. You also need a \caption command: putting an image in a figure environment by itself does not create a caption or a number.

Enable numbered captions

Put this line before \begin{document}:

\setbeamertemplate{caption}[numbered]

Then give the figure a caption. The following complete example uses a framed placeholder instead of an external image, so it compiles without an image file:

\documentclass{beamer}
\setbeamertemplate{caption}[numbered]

\begin{document}

\begin{frame}{A numbered figure}
  \begin{figure}
    \centering
    \rule{4cm}{2cm}
    \caption{A rectangular placeholder for an image.}
    \label{fig:placeholder}
  \end{figure}

  The figure is numbered \ref{fig:placeholder}.
\end{frame}

\end{document}

The caption should display a label like “Figure 1” followed by its text. The \label records the figure counter value, and \ref{fig:placeholder} prints that value in the sentence. Compile the document twice if the reference initially appears as ??, so LaTeX can write and then read the cross-reference information.

Using an actual image

For an image file, load graphicx and replace the \rule placeholder with \includegraphics:

\documentclass{beamer}
\usepackage{graphicx}
\setbeamertemplate{caption}[numbered]

\begin{document}
\begin{frame}{An image}
  \begin{figure}
    \centering
    \includegraphics[width=0.6\textwidth]{example-image}
    \caption{An example image.}
    \label{fig:example}
  \end{figure}
\end{frame}
\end{document}

This version assumes example-image is available with your TeX installation; replace it with the name of your own image file if needed. The key setting is independent of the image format.

Why the number may be missing

Beamer’s default is intentionally different from the usual numbered-caption appearance in many article classes. The figure environment does not guarantee that a visible number will appear: the caption template controls how the caption label is printed. The [numbered] option changes that template so captions include their counter value.

Also check that you have actually written \caption{...}. A \label does not create a caption or display a number; it only saves the current counter value for later reference. Put the label immediately after the caption so it captures the figure’s number rather than some other counter.

Common mistakes

  • Putting the setting after the document starts: put \setbeamertemplate{caption}[numbered] in the preamble, before \begin{document}.
  • Expecting the image to number itself: numbering is tied to \caption, not to \includegraphics or the figure environment alone.
  • Using \label before \caption: move the label after the caption so the reference points to the figure counter.
  • Expecting \ref to print “Figure”: \ref prints only the number. Write “Figure~\ref{fig:example}” if you want the word included in your sentence.

If you want captions without numbers for a particular figure, the simplest approach is to write the explanatory text directly rather than using a numbered \caption. Beamer caption styling can also be customized further, but the numbered template is the standard fix when all figure captions should show their numbers.

References

  1. The beamer class User Guide

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.