1

I want the \listoflistings of minted to appear as a subsection heading. (My \documentclass is scrartcl.)

Things like \printbibliography have a "heading" option, which you can use to define, which heading type it should use. \printacronyms (package acro) has the same. With \KOMAoption{listof}{totocnumbered,leveldown} I can also move \listoffigures from a section heading to a subsection heading, but as for \listoflistings nothing of this works.

Things like this Stackexchange answer did not work and are also "just" about adding it to the TOC and not - which is my main concern - move it one "heading level" down.

I just want a subheading (subsection-like) instead of a heading (section). It would also be nice, if it could appear in the toc.


Basically my TOC should be like this:

  1. Lists
    8.1. List of figures
    8.2. List of listings
    ...

BTW, also asked in GitHub repo.

esdd
  • 85,675
rugk
  • 1,090
  • 1
  • 10
  • 27

2 Answers2

2

With a KOMA-Script class like scrartcl

\addtotoclist[float]{lol}
\renewcommand*\listoflistings{\listoftoc[{\listoflistingscaption}]{lol}}

can be used to get the List of Listings (LOL) under control of package tocbasic. This package is loaded by the KOMA-Script classes und used for TOC, LOF, LOT, ... automatically. The optional argument of \addtotoclist sets owner=float for lol. So the settings of the KOMA-Script option listof={...} will also effect the LOL.

To format the entries for the listings in LOL, you could use

\DeclareTOCStyleEntry[
    level=1,
    indent=1.5em,
    numwidth=2.3em
]{tocline}{listing}

or

\makeatletter
\newcommand\l@listing{\l@figure}
\makeatother

Example:

\documentclass{scrartcl}
\KOMAoption{listof}{totocnumbered,leveldown}

\usepackage{minted}
\addtotoclist[float]{lol}
\renewcommand*\listoflistings{\listoftoc[{\listoflistingscaption}]{lol}}
\DeclareTOCStyleEntry[
    level=1,
    indent=1.5em,
    numwidth=2.3em
]{default}{listing}

\begin{document}
\tableofcontents

\section{Example Section}
\begin{listing}[hb]
\begin{minted}{java}
System.out.println("Test");
\end{minted}
\caption{Test}
\end{listing}

\section{Lists}
\listoffigures
\listoflistings
\end{document}

Result:

enter image description here


Standard classes like article does not define \KOMAoptions and does not load tocbasic. But you can load package tocbasic manually and use:

\documentclass{article}
\usepackage{minted}

\usepackage{tocbasic}
\addtotoclist[float]{lof}
\renewcommand*\listoffigures{\listoftoc[{\listfigurename}]{lof}}
\addtotoclist[float]{lol}
\renewcommand*\listoflistings{\listoftoc[{\listoflistingscaption}]{lol}}
\DeclareTOCStyleEntry[
    level=1,
    indent=1.5em,
    numwidth=2.3em
]{default}{listing}

\doforeachtocfile[float]{%
  \setuptoc{#1}{numbered,leveldown}%
}


\begin{document}
\tableofcontents

\section{Example Section}
\begin{listing}[hb]
\begin{minted}{java}
System.out.println("Test");
\end{minted}
\caption{Test}
\end{listing}

\section{Lists}
\listoffigures
\listoflistings

\end{document}

Result:

enter image description here

esdd
  • 85,675
  • Thanks, this does work. If I understand it correctly, it mostly just is stuff to make it behave like \listoffigures. If so, this seems like a workaround. So do you think this can/needs to be fixed in the minted package itself? – rugk Aug 29 '18 at 12:45
  • Other classes or documents may use other packages (eg. tocloft) for the lists ... So maybe it is more like a feature request to get a numbered heading with lower level and a TOC entry for the LOL. – esdd Aug 29 '18 at 13:21
1

A very basic solution:

  • DIY heading by using \listoftoc* (which is basically \@starttoc)
  • LoL format like LoF

list of listings

Code:

% arara: pdflatex: { shell: 1 }
\documentclass{scrartcl}
\KOMAoption{listof}{totocnumbered,leveldown}
\usepackage{minted}

\makeatletter
\newcommand\l@listing{\l@figure}
\makeatother

\begin{document}

\begin{listing}
\begin{minted}{java}
System.out.println("Test");
\end{minted}
\caption{Test}
\end{listing}

\section*{Lists}
\subsection*{List of listings}
\listoftoc*{lol}

\end{document}
TeXnician
  • 33,589