10

Using the scrartcl class for a report I am writing, I would like to have only the sections show up in the table of contents. Although I manage to do that, the linespread looks too big in my eyes, and I think this is a consequence of the reduced toc depth:

alt text

For this reason, I would like to reduce the linespread locally. I tried to put a {spacing} around my code like this:

\begin{spacing}{0.5}
   \setcounter{tocdepth}{1}
   \rule{\textwidth}{1pt}
   \vspace*{-1cm}
   \tableofcontents
   \vspace*{-0.5cm}
   \rule{\textwidth}{1pt}
\end{spacing}

Which will not work, however. What is the easiest way to decrease the linespread here?

7

You could use the tocstyle package that comes with the KOMA Script bundle. But you will get a warning about the Alpha state of the package so you should use it with caution. At least the below code works as desired.

\documentclass[english]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{tocstyle}
\usepackage{babel}
\usepackage{blindtext}

\setcounter{tocdepth}{1}
\newtocstyle{compact}{%
  \settocfeature[1]{entryhook}{\bfseries}%
  \settocfeature[1]{entryvskip}{0pt plus 2pt}%
  \settocfeature[1]{leaders}{\hfill}%
}
\usetocstyle{compact}

\begin{document}
  \tableofcontents

  \bigskip
  \Blinddocument
\end{document}

And as always, the blindtext package is only for creating dummy text thus not part of the solution.


alt text

  • 1
    The package generating the alpha warning is named tocstyle. – lockstep Dec 11 '10 at 21:28
6

You may use the etoolbox package to patch the command \l@section which is (beside other things) responsible for setting the vertical space before a section entry in the ToC.

\documentclass{scrartcl}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\l@section}{1.0em}{\z@}{}{}
\makeatother

\setcounter{tocdepth}{1}

\begin{document}

\tableofcontents

\section{bla}

\section{blubb}

\section{foo}

\subsection{bar}

\end{document}
  • This depends on the definition of internal commands and does not work with current KOMA-Script release. – Schweinebacke Mar 7 '17 at 10:54
4

Since KOMA-Script 3.20 you can use option tocbeforeskip of command \RedeclareSectionCommand to change the distance before a TOC entry:

\documentclass{scrartcl}[2016/05/10]% Needs at least KOMA-Script 3.20!
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{blindtext}

\setcounter{tocdepth}{1}
\RedeclareSectionCommand[tocbeforeskip=0pt]{section}

\begin{document}
\tableofcontents

\blinddocument\blinddocument\blinddocument\blinddocument
\blinddocument\blinddocument\blinddocument\blinddocument
\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.