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?

2
  • 1
    See documentation of listings, section "Captions". Oct 27, 2011 at 10:11
  • 2
    everything is declared in the documentation of listing -> texdoc listings
    – user2478
    Oct 27, 2011 at 10:12

1 Answer 1

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.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .