129

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}

7 Answers 7

112

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}
3
  • 10
    If I understand correctly, this still requires resetting the figure counter with \setcounter{figure}{0} for each section of the Appendix.
    – akhmed
    Commented May 14, 2015 at 1:12
  • 1
    This breaks hyperref too. Commented Jul 26, 2021 at 23:32
  • In my environment, where I used \part{Appendix} to group my appendixes as chapters, the proposed solution yields the format 'A.0.1' for instance. Hence I turned it to \renewcommand\thefigure{\thechapter.\arabic{figure}}, now working the same as above. Commented Jun 19, 2023 at 10:23
66

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
  • 7
    To make this work for tables, you need to also put \counterwithin{table}{section}. Commented 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
    Commented 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
    Commented Dec 5, 2017 at 16:38
  • 2
    Starts the Appendix and figures with '.1' instead of 'A' for me...
    – Archie
    Commented May 2, 2019 at 12:20
  • 2
    @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} Commented Nov 28, 2021 at 12:29
54

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
  • 9
    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
    Commented Aug 17, 2016 at 13:41
  • 3
    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. Commented Dec 11, 2021 at 15:55
6

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}
1
  • This doesn't work without the proper import
    – Firebug
    Commented Jun 14, 2023 at 7:01
1

I can't comment yet due to low rep but I want to add a note that expands on the answer by @ian-thompson

If you want to add a prefix to all figures and tables in the appendix regardless of which section of the appendix it's in, you can use the code below. Ian's answer generates Figure A.1, A.2 etc in the first section of an appendix but then Figure B.1, B.2 in the next section. If you want static prefix, we remove "\thesection" from the renewcommand line.

\documentclass{article}
\begin{document}
\begin{figure}
\centering\rule{1cm}{1cm}
\caption{This is a figure}
\end{figure}
\appendix


% Change figure labelling
\renewcommand\thefigure{PrefixTextHere.\arabic{figure}}    
\setcounter{figure}{0}  

% Change table labelling
\renewcommand\thetable{PrefixTextHere.\arabic{figure}}    
\setcounter{table}{0}    

\begin{figure}
\centering\rule{1cm}{1cm}
\caption{This is a figure in appendix A}
\end{figure}
\end{document}

In relation to the OP's request the relevant lines to graft into the above would be:

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

A solution that doesn't break hyperref and doesn't require additional packages is as follows:

\documentclass{article}

\usepackage{hyperref}

\begin{document}

Text.

\begin{figure}
  \centering Figure.
  \caption{Main text figure.}
  \label{fig:one}
\end{figure}

This links to a figure in the main text: Fig.~\ref{fig:one}. But this links to a figure in the appendix: Fig.~\ref{fig:Aone}.

\cleardoublepage % just to show that the cross-references go to different places

\appendix

\counterwithin*{figure}{part}

\stepcounter{part}

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

This is the Appendix.

\begin{figure}
  \centering Appendix Figure.
  \caption{A figure in the Appendix.}
  \label{fig:Aone}
\end{figure}


\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .