2

in my thesis I have a few R scripts at the very end, as an Appendix. Within the appendix itself I want the \lstlistoflistings.

This formats the list as a chapter (same as for the toc).

How can I format it as section? I just want to avoid the page break after the chapter title and have the list right after it, with a smaller font.

Here is a minimal working example

\documentclass{report}  

\usepackage{listings}
    \lstset{language=R}
    \renewcommand{\lstlistlistingname}{List of R scripts}


\begin{document}
\tableofcontents

\chapter{the first chapter}
    \section{section1}
some text
\chapter{the second chapter}

\addcontentsline{toc}{chapter}{Appendix A}
\chapter*{Appendix A}
\lstlistoflistings

\newpage
\begin{lstlisting}[caption=A script]
some code
\end{lstlisting}

\begin{lstlisting}[caption=Another script]
some more code
\end{lstlisting}

\end{document}

Thanks!

AMusu
  • 23

2 Answers2

2

\lstlistoflistings (what a easy to remember name ;-)) uses \tableofcontents internally actually and redefines \@starttoc slightly to apply, but still has the \chapter* heading of \tableofcontents.

In my point of view, it's easier to apply a redefinition of \lstlistoflistings such that it has the same appearance as \tableofcontents.

\documentclass{report}  
\usepackage{listings}
\lstset{language=R}
\renewcommand{\lstlistlistingname}{List of R scripts}


\makeatletter
\renewcommand{\lstlistoflistings}{%
  \begingroup
  \clearpage
  \section*{\lstlistlistingname% Taken from `article.cls`....
   \@mkboth{%
     \MakeUppercase\lstlistlistingname}{\MakeUppercase   
     \lstlistlistingname}
   }%
  \@starttoc{lol}
  \endgroup
}
\makeatother




\begin{document}
\tableofcontents

\chapter{the first chapter}
\section{section1}
some text
\chapter{the second chapter}

\addcontentsline{toc}{chapter}{Appendix A}
\chapter*{Appendix A}
\lstlistoflistings

\newpage
\begin{lstlisting}[caption=A script]
some code
\end{lstlisting}

\begin{lstlisting}[caption=Another script]
some more code
\end{lstlisting}

\end{document}

enter image description here

0

You could load tocbasic and scrhack. Then you can use \setuptoc{lol}{leveldown}:

\documentclass{report}

\usepackage{scrhack}
\usepackage{tocbasic}
\setuptoc{lol}{leveldown}

\usepackage{listings}
    \lstset{language=R}
    \renewcommand{\lstlistlistingname}{List of R scripts}

\begin{document}
\tableofcontents

\chapter{the first chapter}
    \section{section1}
some text
\chapter{the second chapter}
\chapter*{Appendix A}
\addcontentsline{toc}{chapter}{Appendix A}
\lstlistoflistings
\newpage
\begin{lstlisting}[caption=A script]
some code
\end{lstlisting}
\begin{lstlisting}[caption=Another script]
some more code
\end{lstlisting}
\end{document}

enter image description here

I have changed the order of \chapter* and \addcontentsline to get the right page number in ToC.

esdd
  • 85,675