TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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
up vote 6 down vote accepted

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


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


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.

share|improve this answer
Thank you very much! – strauberry Oct 27 '11 at 11:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.