115

I want to "reset" the figure counting in my document when the appendix starts, and follow a different pattern than 1, 2, 3... Specifically, I want figures in the appendix to start with A.1, A.2 onward, instead of continuing on from the main document. How can I do this?

\documentclass[twoside]{article}

\usepackage{graphicx,dblfloatfix}


\usepackage{titlesec}% Allows customization of titles
\titleformat{\section}[block]{\large\scshape\centering{\Roman{section}.}}{}{1em}{} % Change the look of the section titles 

\begin{document}

\section{Introduction}
\subsection{Problem description}
Blah blah
\begin{figure}[!htb]
    \centering 
    \includegraphics{decon}
    \caption{Call this figure 1.}
\label{fig1} 
\end{figure}
\appendix
\section{Figures}

\begin{figure}[!htb]
    \centering 
    \includegraphics{decon}
    \caption{Call this figure A.1.}
\label{figa1} 
\end{figure}

\begin{figure}[!htb]
    \centering 
    \includegraphics{decon}
    \caption{Call this figure A.2.}
\label{figa2} 
\end{figure}

\end{document}

5 Answers 5

95

Redefine \thefigure when your appendices start, and set the figure counter to zero at the beginning of each appendix.

\documentclass{article}
\begin{document}
\begin{figure}
\centering\rule{1cm}{1cm}
\caption{This is a figure}
\end{figure}
\appendix
\renewcommand\thefigure{\thesection.\arabic{figure}}    
\section{A nice appendix}
\setcounter{figure}{0}    
\begin{figure}
\centering\rule{1cm}{1cm}
\caption{This is a figure in appendix A}
\end{figure}
\end{document}
2
  • 8
    If I understand correctly, this still requires resetting the figure counter with \setcounter{figure}{0} for each section of the Appendix.
    – akhmed
    May 14, 2015 at 1:12
  • 1
    This breaks hyperref too. Jul 26, 2021 at 23:32
57

You can use the chngcntr package which includes the command \counterwithin.

Using this as \counterwithin{figure}{section} changes the figure numbering from that point on so that the section number is included and resets the numbering of figures at the beginning each subsequent section. An example is:

\documentclass{article}

\usepackage{chngcntr}

\begin{document}

\section{Introduction}

\subsection{Problem description}

\begin{figure}[htp]
  \centering Figure
  \caption{Call this figure 1.}
  \label{fig1}
\end{figure}

\appendix
\counterwithin{figure}{section}

\section{Figures}

\begin{figure}[htp]
  \centering Figure
  \caption{Call this figure A.1.}
  \label{figa1}
\end{figure}

\begin{figure}[htp]
  \centering Figure
  \caption{Call this figure A.2.}
  \label{figa2}
\end{figure}

\end{document}

Sample output

11
  • 6
    To make this work for tables, you need to also put \counterwithin{table}{section}. Nov 22, 2013 at 3:06
  • 7
    With this solution, hyperref links properly to the appendix figure (with the accepted solution, hyperref links to Figure 1 in stead of Figure A.1, etc).
    – midobal
    Mar 31, 2016 at 13:06
  • @midobal are hyperref links the same thing here as cref [from the cleveref package] links? 'Cause these work correctly for me with the accepted solution.
    – jan-glx
    Dec 5, 2017 at 16:38
  • 1
    Starts the Appendix and figures with '.1' instead of 'A' for me...
    – Archie
    May 2, 2019 at 12:20
  • 1
    @SamuelSaari The easiest way would be to use \section* for the heading plus \refstepcounter{section} just after the heading. If you need a contents entry for the heading, you can add that with \addcontentsline{toc}{section}{Figures} Nov 28, 2021 at 12:29
46

A simple way to prepend an A to your appendix figures and to have the counter reset is to paste the following two lines before your first figure of the appendix.

\renewcommand{\thefigure}{A\arabic{figure}}

\setcounter{figure}{0}

as illustrated here.

2
  • 6
    And, obviously, \renewcommand{\thetable}{A.\arabic{table}} and \setcounter{table}{0} (note that I prefer using the dot in the middle, e.g. A.1.. just to say, this solution is no less general than the other twos)
    – Antonello
    Aug 17, 2016 at 13:41
  • 1
    This was the best solution for me, because references still work, the chapter number of the appendix is not affected and the figure numbering is customizable. Dec 11, 2021 at 15:55
5

I added - hbAppendixPrefix to change prefix easily - equation numbering, too

\newcommand{\hbAppendixPrefix}{A}
%
\renewcommand{\thefigure}{\hbAppendixPrefix\arabic{figure}}
\setcounter{figure}{0}
\renewcommand{\thetable}{\hbAppendixPrefix\arabic{table}} 
\setcounter{table}{0}
\renewcommand{\theequation}{\hbAppendixPrefix\arabic{equation}} 
\setcounter{equation}{0}
4

This is the solution for everything which manages both figures and tables in appendix

\appendix
\appendixpage
\addappheadtotoc
\counterwithin{figure}{section}
\counterwithin{table}{section}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.