7

I'm trying to add a list of code listings to my document, with a reference to it in the TOC. By simply calling

\lstlistoflistings

I end up getting everything I need (the list of listings, an entry in the TOC, etc) EXCEPT for the fact that the entry is always named 'Contents'. I was able to change the title of the listing page itself by running the command

\renewcommand\lstlistlistingname{List of Code}

but this doesn't change the reference in the table of contents.

EDIT: Adding a minimal working example

\documentclass{Thesis}

\usepackage{listings}

\begin{document}
\renewcommand\lstlistlistingname{List of Code}

\tableofcontents

\lstlistoflistings

\lstset{caption=Some Code}
\begin{lstlisting}
Some code
\end{lstlisting}
\end{document}

1 Answers1

13

You see only "Contents" in the Table of Contents because that is the header of the ToC itself.

If you want to have an entry for your "List of Code", add the following lines

\clearpage
\addcontentsline{toc}{chapter}{\lstlistlistingname}

just before

\lstlistoflistings

Complete MWE:

\documentclass{Thesis}

\usepackage{listings}

\begin{document}
\renewcommand\lstlistlistingname{List of Code}

\tableofcontents

\clearpage
\addcontentsline{toc}{chapter}{\lstlistlistingname}

\lstlistoflistings

\lstset{caption=Some Code}
\begin{lstlisting}
Some code
\end{lstlisting}
\end{document} 

Output:

enter image description here

karlkoeller
  • 124,410