75

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}
63

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}
  • 5
    If I understand correctly, this still requires resetting the figure counter with \setcounter{figure}{0} for each section of the Appendix. – akhmed May 14 '15 at 1:12
39

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

  • 3
    To make this work for tables, you need to also put \counterwithin{table}{section}. – generic_user Nov 22 '13 at 3:06
  • 1
    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 '16 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 '17 at 16:38
  • Starts the Appendix and figures with '.1' instead of 'A' for me... – Archie May 2 at 12:20
  • @Archie That sounds like you are using a class such as report or book where the top level units are chapters and/or you have used \section*. Adjust the \counterwithin command to your set-up. If you have problems with that, please post a new question. – Andrew Swann May 2 at 13:00
23

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
    This solution is less general than the others proposed, as it fixed the "appendix number" to A. – Werner Nov 3 '14 at 23:05
  • 2
    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 '16 at 13:41
3

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}

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.