4

I want to have per-subsection figure numbering in the appendix of the following MWE: it should read "Figure A.1" instead of "Figure 2".

\documentclass{article}

\usepackage{amsmath}  
\numberwithin{equation}{section}

\usepackage[demo]{graphicx}   
\usepackage{caption}
\captionsetup[figure]{figurewithin=section}

\newcommand*{\appheading}[1][Appendix]{%
  \setcounter{secnumdepth}{0}\section{#1}\setcounter{secnumdepth}{3}%
  \renewcommand*{\thesubsection}{\Alph{subsection}}
  \numberwithin{equation}{subsection}  
}

\begin{document}

\section{Foo} 

\begin{equation}
  x = 4
\end{equation}

\begin{figure}[htbp!]
  \centering
  \includegraphics{foo}
  \caption{Fooo}
\end{figure}

\appheading
\appendix
\subsection{Baz}

\begin{equation}
  y = 3
\end{equation}

\begin{figure}[htbp!]
  \centering
  \includegraphics{baz}
  \caption{Baz}
\end{figure}

\end{document}

I tried changing the thefigure counter and also using the chngcntr package but couldn't make it work.

  • 1
    Something like this should do what you want. \setcounter{figure}{0} \renewcommand{\thefigure}{Figure \Alph{chapter}.\arabic{figure}} – Nicholas Hamilton May 31 '13 at 21:25
  • figurewithin=section should be directly passed to the caption package, i.e. \usepackage[figurewithin=section]{caption} or \captionsetup{figurewithin=section} (without the [figure] stuff). – Axel Sommerfeldt Jun 1 '13 at 12:23
4

Use \numberwithin instead of the figurewithin option:

\documentclass{article}

\usepackage{amsmath}  
\numberwithin{equation}{section}

\usepackage[demo]{graphicx}   
\usepackage{caption}
\numberwithin{figure}{section}

\newcommand*{\appheading}[1][Appendix]{%
  \setcounter{secnumdepth}{0}\section{#1}\setcounter{secnumdepth}{3}%
  \renewcommand*{\thesubsection}{\Alph{subsection}}
  \numberwithin{equation}{subsection}
  \numberwithin{figure}{subsection}
}

\begin{document}

\section{Foo} 

\begin{equation}
  x = 4
\end{equation}

\begin{figure}[htbp!]
  \centering
  \includegraphics{foo}
  \caption{Fooo}
\end{figure}

\appheading
\appendix
\subsection{Baz}

\begin{equation}
  y = 3
\end{equation}

\begin{figure}[htbp!]
  \centering
  \includegraphics{baz}
  \caption{Baz}
\end{figure}

\end{document}

enter image description here


Why don't you use \part* instead of those tricks?

\documentclass{article}

\usepackage{amsmath}  
\numberwithin{equation}{section}

\usepackage[demo]{graphicx}   
\usepackage{caption}
\numberwithin{figure}{section}

\newcommand*{\appheading}[1][Appendix]{%
  \part*{#1}
  \renewcommand*{\thesection}{\Alph{section}}
}

\begin{document}

\section{Foo} 

\begin{equation}
  x = 4
\end{equation}

\begin{figure}[htbp!]
  \centering
  \includegraphics{foo}
  \caption{Fooo}
\end{figure}

\appheading
\appendix
\section{Baz}

\begin{equation}
  y = 3
\end{equation}

\begin{figure}[htbp!]
  \centering
  \includegraphics{baz}
  \caption{Baz}
\end{figure}

\end{document}
  • I don't use part because: (i) with the tricks I can control pdf bookmarks easily (allowing them to go straight to the section heading) (ii) I like the appendix to be a section rather than a part. Excellent answer BTW. It never ceases to amaze me how much you know about TeX. – petobens May 31 '13 at 21:51
3

insert these two lines immediately after the line \subsction{Baz}:

\setcounter{figure}{0}
\setcounter{section}{1}

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.