Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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
1  
See documentation of listings, section "Captions". –  Ulrike Fischer Oct 27 '11 at 10:11
2  
everything is declared in the documentation of listing -> texdoc listings –  Herbert Oct 27 '11 at 10:12
add comment

1 Answer

up vote 6 down vote accepted

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.

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

Your Answer

 
discard

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.