4

In my appendix I have figures and listings. The figures are now labeled very well (see this question). Now I have the same issue with listings: in the appendix it is labeled as A.1, but in my text only as 1. What is the corresponding command to \thefigure I have to redefine for a listing?

strauberry
  • 3,255

1 Answers1

6

The name you're looking for is \thelstlisting. Example:

\renewcommand*{\thelstlisting}{\arabic{lstlisting}}

Perhaps consider using a package for customizing counters, such as chngcntr:

\usepackage{chngcntr}
\AtBeginDocument{\counterwithin{lstlisting}{chapter}}

This would also take care of resetting the counter at the beginning of each chapter.

Note, the counter lstlisting is defined at the beginning at the document, so you can work with it after \begin{document} or, as I showed, using \AtBeginDocument.

Edit: following Ulrikes comment: there are built-in features of the listings package for that, such as numberbychapter=true, you can use. However, for very consistent behavior it might be worth considering to treat the lstlisting counter exactly like the figure counters etc. in the same place of your preamble, instead of on one side customizing some counters and on the other side using similar package options.

Stefan Kottwitz
  • 231,401