# How to modify the equivalent of \thefigure for listings?

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?

-
See documentation of listings, section "Captions". –  Ulrike Fischer Oct 27 '11 at 10:11
everything is declared in the documentation of listing -> texdoc listings –  Herbert Oct 27 '11 at 10:12

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.

-
Thank you very much! –  strauberry Oct 27 '11 at 11:36