# Omit the the .1 from figure numbering when there's only one figure in a chapter

In the book class, figures are by default numbered as \thechapter.\arabic{figure}. However, the {figure} numbering is redundant when there is only a single figure in a chapter.

In such a case, how do I remove the \arabic{figure} from the figure label, so the single figure is just labelled and referenced as Figure \thechapter instead of Figure \thechapter.\arabic{figure}

In my MWE, I have chapter 1 containing two figures (with default labeling) and chapter 2 containing only one figure. How do I get that figure to only be labeled as Figure 2 instead of Figure 2.1

\documentclass{book}
\usepackage{graphicx}

\begin{document}

\chapter{First chapter with two figures}

In this chapter, Figures \ref{fig1.1} and \ref{fig1.2} are labeled as intended.

\begin{figure}[tbh]
\centering
\includegraphics[height=3cm]{example-image-a}
\caption{Figure is labeled 1.1 as intended}
\label{fig1.1}
\end{figure}

\begin{figure}[tbh]
\centering
\includegraphics[height=3cm]{example-image-b}
\caption{Figure is labeled 1.2 as intended}
\label{fig1.2}
\end{figure}

\chapter{Second chapter with one single figure}

In this chapter the only Figure \ref{fig2} should be labeled and referenced as just 2, not 2.1.

\begin{figure}[tbh]
\centering
\includegraphics[height=3cm]{example-image-c}
\caption{This is the only figure in this chapter. The .1 in the numbering is redundant and I would like to remove it.}
\label{fig2}
\end{figure}

\end{document}


The reason why I want to remove the \arabic{figure} from lone figures is because a .1 could be interpreted as an implication for at least a .2.

Note that the numbering I am suggesting keeps all figure labels unique.

• Just a thought. If you redefine figure labelling to a single (figure) number just within a chapter, hence locally, I think you are going to confuse readers, especially if you have more than one this kind of chapters. The global format would still be chapter.figure and figure numbers would still get reset per chapters. You end up with a number of figures labelled as Figure 1: .... Sep 24 at 11:34
• I think you misunderstood my question. In the book class, figures are by default labeled as \thechapter.\arabic{figure}. My question was how to remove the \arabic{figure} part of the label, not the \thechapter (and that only if there is a single figure in a chapter). So all figure labels would indeed still be unique. I added that description in my original question too. Cheers Sep 25 at 9:13
• In that case, you just need to redefine figure numbering to \renewcommand*{\thefigure}{\arabic{chapter}} for chapters with a single figure. Sep 25 at 9:19

If you think there are more chapters containing labels only with a single figure, I would suggest to turn off resetting a figure number per chapter. This way labels will remain unique across the document.

One way to achieve the above is to use

\counterwithout*{figure}{chapter}


a starred version, so that format of \thefigure remains the same across the document. Then, redefine the label only sparsely in those figure environments which does not require chapter numbers. I created a new environment called slfigure for this purpose which contain the line

\renewcommand*{\thefigure}{\arabic{figure}}


Here is the example

\documentclass[openany]{book}   % [openany] only for demonstration to avoid empty pages
\usepackage{graphicx}

\counterwithout*{figure}{chapter}    % Prevents from resetting figure numbers
\adjustboxset{width=0.5\linewidth}   % To avoid repetition with \inlcudegraphics[width=0.5\linewidth]{...}

% This environment redefines figure labelling, locally
\NewDocumentEnvironment{slfigure}{O{} +b}{
\begin{figure}[#1]
\renewcommand*{\thefigure}{\arabic{figure}}
#2
\end{figure}
}{}

\begin{document}
\chapter{Chapter with only one figure}
In this chapter the only Figure \ref{fig1} should be referenced as just 1, not 1.1.

\begin{slfigure}[tbh]
\centering
\includegraphics{example-image-a}
\caption{Single figure}
\label{fig1}
\end{slfigure}

\chapter{Chapter with several figures}
In this chapter, the Figures \ref{fig2.2} and \ref{fig2.3} can be referenced as intended.

\begin{figure}[tbh]
\centering
\includegraphics{example-image-b}
\caption{Figure is labeled 2.2 as intended}
\label{fig2.2}
\end{figure}

A sentence between figures

\begin{figure}[tbh]
\centering
\includegraphics{example-image-c}
\caption{Figure is labeled 2.3 as intended}
\label{fig2.3}
\end{figure}

\chapter{Chapter with only one figure}
The second chapter with a single Figure~\ref{fig:4}

\begin{slfigure}[tbh]
\centering
\includegraphics{example-image}
\caption{Single figure no. 4}
\label{fig:4}
\end{slfigure}
\end{document}

• Thanks :-D This does exactly what I wanted. In fact, I do want the figure counter to reset per chapter (I think it's actually the default behavior.). But it works great without that line too. Love this community :-D Sep 25 at 8:58
• You could also redefine numbering to matching a chapter number: \renewcommand*{\thefigure}{\arabic{chapter}}, which would prevent from having repeated Figure 1: .... Sep 25 at 9:15
• Welcome to TeX.SE!
• Your question is not entirely clear: how should be numbered figures which are inserted before \section{...}?
• I anticipate, that the same as if no sections in chapter
• In this case try to add in your preamble the following code snippet:

\usepackage{etoolbox}
\AtBeginEnvironment{figure}%
{
\ifnum\arabic{section}=0
\renewcommand\thefigure{\thechapter.\arabic{figure}}
\else
\renewcommand\thefigure{\thesection.\arabic{figure}}
\fi
}

• complete MWE (a wee a bit changed your MWE)
\documentclass{book}
\usepackage{graphicx}

\usepackage{etoolbox}
\AtBeginEnvironment{figure}%
{
\ifnum\arabic{section}=0
\renewcommand\thefigure{\arabic{figure}}
\else
\renewcommand\thefigure{\thesection.\arabic{figure}}
\fi
}

\begin{document}

\chapter{Chapter with only one figure}

In this chapter the only Figure \ref{fig1} should be referenced as just 1, not 1.1.

\begin{figure}[ht]
\centering
\includegraphics[height=3cm]{example-image-a}
\caption{This is the only figure in this chapter. The .1 in the numbering is redundant and I would like to remove it.}
\label{fig1}
\end{figure}

\begin{figure}[ht]
\centering
\includegraphics[height=3cm]{example-image-a}
\caption{This is the only figure in this chapter}
\label{fig2}
\end{figure}

\chapter{Chapter with several figures}

\begin{figure}[ht]
\centering
\includegraphics[height=3cm]{example-image-a}
\caption{Figure is labeled 2.1 as intended}
\label{fig2.1}
\end{figure}

\section{first section in the second chapter}
\begin{figure}[ht]
\centering
\includegraphics[height=3cm]{example-image-a}
\caption{Figure is labeled 2.2 as intended}
\label{fig2.2}
\end{figure}

\end{document}


gives

• Hi, thanks for your suggestion. By default, the book document class ignores sections and just labels figures as \thechapter.\arabic{figure}. I don't want to change anything about that. But your code does in fact describe the situation when figures are to be labeled as \thechapter.\thesection.\arabic{figure}, which is also valid. Sep 25 at 9:09