4

Why does uncommenting the (IMHO innocent) call to \settocdepth{chapter} in the following MWE make the list of listings become blank? Or rather: what can I do to both preserve a chapter-only TOC for the appendix and keep the list of listings "alive"?

\documentclass{memoir}
\usepackage{listings}

\begin{document}
\tableofcontents
\lstlistoflistings
\newpage

\chapter{A chapter}
\begin{lstlisting}[float,caption={Foo},label={lst:foo}]
Foo code
\end{lstlisting}
\newpage

%\settocdepth{chapter} % uncomment --> list of listings empty
\appendix
\chapter{Foo}
Bar
\end{document}

1 Answer 1

3

The command \settocdepth{chapter} causes

\changetocdepth{0}

to be written in the .toc file, so this setting continues when the list of listings is read in for typesetting.

Just reset it:

\documentclass{memoir}
\usepackage{listings}

\begin{document}
\tableofcontents

\settocdepth{subsection} 
\lstlistoflistings
\newpage

\chapter{A chapter}
\section{A section}
\begin{lstlisting}[float,caption={Foo},label={lst:foo}]
Foo code
\end{lstlisting}
\newpage

\settocdepth{chapter} 
\appendix
\chapter{Foo}
\section{A section}
Bar
\end{document}

enter image description here

2
  • Thanks, that worked! I don't exactly understand why this is happening to a list of listings, but not an identically placed list of figures/tables.
    – ojdo
    Sep 23, 2015 at 14:57
  • 1
    @ojdo \lstlistoflistings uses the same framework as \tableofcontents, only changing the heading.
    – egreg
    Sep 23, 2015 at 15:06

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.