[Tex/LaTex] How to add \lstlistoflistings to the table of contents

listingstable of contents

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.

Best Answer

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}