3

There seems to be some negative interaction between Koma Script (using version 3.11a) and the lstdoc package in my example document. The MWE works nicely when I comment out \usepackage{lstdoc} but when I include it the formatting of the table of contents is messed up. Here is the example document:

\documentclass[
a4paper,
titlepage
]{scrbook}

\usepackage{lstdoc}

\begin{document}
\tableofcontents

\section{test1}
test test
\end{document}

The output without lstdoc looks as follows enter image description here

whereas with the package included this happens: enter image description here

Is there any workaround to this problem? I want to the line because I am using the alternative to the glossaries package from this question which requires the lstdoc package. I noticed that hyperref is also pulled in if lstdoc is used but hyperref alone does not cause any problems.

1 Answer 1

2

The problem is that lstdoc.sty redefines some of the \l@... family of commands in charge of typesetting the entries for the sectional units in the ToC. For example, \l@section is defined in lstdoc.sty as

\newcommand*\l@section[2]{%
    \addpenalty\@secpenalty
    \addvspace{.25em \@plus\p@}%
    \setlength\@tempdima{1.5em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
    \endgroup}

whereas the definition for \l@section in scrbook.cls is

\newcommand*\l@section{\bprot@dottedtocline{1}{1.5em}{2.3em}}

In order to recover the original definitions you can redefine the \l@... commands in the preamble of your document to be the ones used for scrbook.cls. So for example:

\documentclass[a4paper,titlepage]{scrbook}
\usepackage{lstdoc}

\makeatletter
\renewcommand*\l@section{\bprot@dottedtocline{1}{1.5em}{2.3em}}
\makeatother

\begin{document}
\tableofcontents

\section{test1}
test test
\end{document}

produces

enter image description here

which is (up to the colored hyperlink) the original formatting. Similar redefinitions will have to be made for some of the other \l@... commands corresponding to the other sectional units that will go to the ToC and which \l@... commamds are redefined by lstdoc.sty.

The following example code shows these redefinitions necessary to obtain the original formatting for ToC entries from \chapter down to \subparagraph:

\documentclass[a4paper,titlepage]{scrbook}
\usepackage{lstdoc}

% all sectional units will be numbered and will go to the ToC
\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}

\makeatletter
\renewcommand*\l@section{\bprot@dottedtocline{1}{1.5em}{2.3em}}
\renewcommand*\l@subsection{\bprot@dottedtocline{2}{3.8em}{3.2em}}
\renewcommand*\l@subsubsection{\bprot@dottedtocline{3}{7.0em}{4.1em}}
\makeatother

\begin{document}
\tableofcontents

\chapter{Test Chapter}
\section{Test Section}
\subsection{Test Subsection}
\subsubsection{Test Subsubsection}
\paragraph{Test Paragraph}
\subparagraph{Test Subparagraph}

\end{document}

enter image description here

2
  • Thank you! Now the table of contents is restored to it's old beauty.
    – Alexander
    Jul 19, 2012 at 9:52
  • Since KOMA-Script 2015/01/14 v3.15 you should not longer redefine \l@… using \bprot@dottedtocline. The better (and easier) solution would be to use \RedeclareSectionCommands{section,subsection,subsubsection}. Can you change/add this to the answer? May 29, 2017 at 5:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .