3

Consider the following simplified TOC style (yes, the real-life version does look better than this MWE). Thing looks okay except for the fact that the first TOC line lies one line below where it should be. Compare page 1 and 2.

This is a result of the space between the chapter entries in TOC being implemented via \addvspace{\baselineskip} as a ›before-code‹ (as the titletoc doc calls it): before every chapter entry, an empty line is produced. Which is good except before the very first entry. How do we get rid of it? My experiments with negative space haven't been too successful, and using the titlesec ›after-code‹ isn't an option either, as it's not invoked after the entire chapter chunk, but after that chunk's chapter line (option B in this MWE).

Note that \addvspace{\baselineskip} is the vertical spacing method officially endorsed by titlesec. It seems odd that apparently extra work has to be done in order to restore LaTeX's standard behavior: the problem disappears if we don't redefine the TOC chapter style or unload titlesec entirely.

enter image description here

\documentclass{scrreprt}
\usepackage{blindtext,titletoc}

\titlecontents{chapter}[0em]%
{\addvspace{\baselineskip}}% (A)
%{}% (B)
{\thecontentslabel\enskip}%
{}%
{\quad\emph{\thecontentspage}}%
[]% (A)
%[\addvspace{\baselineskip}] % (B)

\titlecontents{section}[0em]{}
{\thecontentslabel\enskip}%
{}%
{\quad\emph{\thecontentspage}}%
[]

\begin{document}
\tableofcontents

\chapter{Lorem}\blindtext
\chapter{Lorem}\blindtext
\chapter{Lorem}\blindtext

\section{Ipsum}\blindtext
\section{Ipsum}\blindtext
\section{Ipsum}\blindtext

\end{document}
2
  • Maybe \AfterTOCHead[toc]{\vspace*{-\baselineskip}} in the preamble will help.
    – esdd
    Apr 7, 2015 at 14:01
  • I have some resentments against the idea of adding space, and then removing it, but yes, it does work! Feel free to post this as an answer.
    – Nils L
    Apr 7, 2015 at 16:29

2 Answers 2

3

Here you are:

\documentclass{scrreprt}
\usepackage{blindtext,titlesec, titletoc}
\uspackage{etoolbox}
\titlecontents{chapter}[0em]%
{\ifnumgreater{\thecontentslabel}{1}{\addvspace{\baselineskip}}{}}% (A)
%{}% (B)
{\thecontentslabel\enskip}%
{}%
{\quad\emph{\thecontentspage}}%
[]% (A)
%[\addvspace{\baselineskip}] % (B)

\titlecontents{section}[0em]{}
{\thecontentslabel\enskip}%
{}%
{\quad\emph{\thecontentspage}}%
[]

\begin{document}
\tableofcontents

\chapter{Lorem}\blindtext
\chapter{Lorem}\blindtext
\chapter{Lorem}\blindtext

\section{Ipsum}\blindtext
\section{Ipsum}\blindtext
\section{Ipsum}\blindtext

\end{document}

enter image description here

2
  • This is great indeed, except for people whose first chapter is an unnumbered one, or who don't use chapter numbers at all: \addchap{Preface} or \setcounter{secnumdepth}{0}.
    – Nils L
    Apr 7, 2015 at 16:28
  • Perhaps with the unnumbered version of \titlecontents someting might be done…
    – Bernard
    Apr 7, 2015 at 16:55
1

Here's a simple way to do this which doesn't depend on the numbering of the chapters at all. We simply flag the first TOC entry with a conditional, and set it to false thereafter.

\documentclass{scrreprt}
\usepackage{blindtext,titletoc}
\newif\iffirst\firsttrue

\titlecontents{chapter}[0em]%
{\iffirst\global\firstfalse\else\addvspace{\baselineskip}\fi}% (A)
%{}% (B)
{\thecontentslabel\enskip}%
{}%
{\quad\emph{\thecontentspage}}%
[]% (A)
%[\addvspace{\baselineskip}] % (B)

\titlecontents{section}[0em]{}
{\thecontentslabel\enskip}%
{}%
{\quad\emph{\thecontentspage}}%
[]

\begin{document}
\tableofcontents

\chapter{Lorem}\blindtext
\chapter{Lorem}\blindtext
\chapter{Lorem}\blindtext

\section{Ipsum}\blindtext
\section{Ipsum}\blindtext
\section{Ipsum}\blindtext

\end{document}

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.