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!

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.

1

\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

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.