11

can someone tell me, how to create an entry for the \lstlistoflistings command in the TOC? I want, that you can see the page number where the list can be found.

  • Which documentclass do you use? – Marco Daniel Feb 9 '13 at 12:30
  • I use \documentclass{scrreprt} – Benny Neugebauer Feb 9 '13 at 12:53
11

The solution depends on your documentclass. If you are using a KOMA-class you can use the option listof. Of course you can set this key local to \lstlistoflistings

\documentclass[listof=totoc]{scrartcl}
\usepackage{scrhack}
\usepackage{listings}
\begin{document}
\tableofcontents
\lstlistoflistings

\section{foo}
text
\begin{lstlisting}[caption={A listing}]
(Listing content)
\end{lstlisting}
\end{document}

enter image description here

For the standard classes the standard command \addcontentsline should be used.

\documentclass{article}
\usepackage{listings}
\begin{document}
\tableofcontents
\addcontentsline{toc}{section}{Listings}
\lstlistoflistings

\section{foo}
text
\begin{lstlisting}[caption={A listing}]
(Listing content)
\end{lstlisting}
\end{document}
  • Thanks for the info but how do I get the listings entry without numbering? – Benny Neugebauer Feb 9 '13 at 12:57
  • @BennyNeugebauer: Which number do you mean? – Marco Daniel Feb 9 '13 at 12:58
  • 1
    You can also use chapter instead of section: \addcontentsline{toc}{chapter}{Listings} – Thiago Perrotta Jun 16 '17 at 19:20
3

For the case anyone uses the tocbibind package, which main purpose is the handling of "list of tables/figures/etc." in the Table of Contents, the documentation already provides a solution:

There are packages, such as listings and ccaption, that provide new Listof lists. These can be handled by the tocbibind package in a similar manner to the usual Listofs. Two examples are given below. The listings package version 0.2 provides a \lstlistoflistings command to print a list of listings. The header name for this list is in \lstlistingname and the listing file has the extension lol. This can be treated just like the \listoffigure, etc., commands. To add the List of Listings header to the ToC do:

\renewcommand{\lstlistoflistings}{\begingroup
\tocfile{\lstlistingname}{lol}
\endgroup}

http://www.ctex.org/documents/packages/bibref/tocbibind.pdf

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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