Currently, I have an issue that in my thesis the numbering of listings in the appendix is not as desired. I currently only get Listing 1 as the numbering of the first listing in the first Appendix, instead of Listing A.1. For figures and tables, I already achieve the desired behavior, that is, the figures and tables get, for instance, the following numbering: Figure A.1.

I just discovered that at the appendix I use the following Latex commands to, obviously, control the behavior of figure and table numbering:


What do I have to add to get this to work for listings in the appendix?

  • okay the following command seems to do the trick for me: \renewcommand{\thelstlisting}{\Alph{section}.\arabic{lstlisting}} – beta Jun 16 '16 at 12:56
  • You should use \thesection as part of \thefigure, \thetable and \thelstlisting, not \Alph{section}. That implies a recursive definition which will change with every change to \thesection. – Werner Jun 16 '16 at 18:28
  • @beta: Please give some feedback to the solution whether this is what you requested! – user31729 Jun 19 '16 at 20:06
  • as i said in my comment (see tex.stackexchange.com/questions/315056/…) I found a solution. can this be converted to an answer? – beta Jun 20 '16 at 12:56

The \counterwithin command from chngcntr package does the correct setup without explicit \renewcommand statements of \the.... macros.

The only macro that has to be redefined is \thesection in order to use \Alph{...}.








\begin{lstlisting}[language=C,caption={Foo listing}]


int main(int argc,char **argv)
  printf("Hello World!\n");


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.