3

I want to understand what are the lengths dimension #1 and #2 in the following example.

Moreover, is the blue dimension in the picture equals the length of \parskip?

How can I control the dimensions #1 and #2 with titletoc? I created two new lengths in the MWE, how can I pass them as the correct arguments of \titlecontents{section}[]{}{}{}{}[] and \titlecontents{chapter}[]{}{}{}{}[]?

enter image description here

% !TEX TS-program = xelatex
\documentclass{book}
\usepackage{fontspec}
\setlength{\parskip}{10pt}
\setlength{\parindent}{0pt}

\usepackage{titletoc}
  \dottedcontents{section}[3.8em]{}{2.3em}{0pc}
  \dottedcontents{subsection}[6.1em]{}{3.2em}{0pc}

\newlength\dimone \setlength\dimone{8pt}  % << new length
\newlength\dimtwo \setlength\dimtwo{14pt} % << new length

\usepackage[english]{babel}
\begin{document}
\tableofcontents
\chapter{First chapter}
\section{one}
\subsection{a}
\subsection{b}
\subsection{c}
\section{two}
\section{three}
\section*{Summary}
\addcontentsline{toc}{section}{Summary}
\section*{Exercises}
\addcontentsline{toc}{section}{Exercises}
\chapter{second chapter}
\section*{Introduction}
\addcontentsline{toc}{section}{Introduction}
\section{one}
\section{two}
\section{three}
\end{document}
3
  • I stand corrected. The 10pt is only added to the lof and lot files (\addvspace {10\p@ }) You need to look at \l@chapter, \l@section etc. to get the vertical space (ignore that some of them are negative). Keep in mind that the code being implemented could be modified from the default from book.cls. Apr 3, 2023 at 21:46
  • \l@chapter from book.cls uses \vskip 1.0em \@plus\p@ while the rest use \vskip \z@ \@plus.2\p@ (from \@dottedtocline). In other words, 0pt plus glue., Since each entry is a paragraph, \parskip is being added as well. Apr 3, 2023 at 22:03
  • \tableofcontents uses \chapter* which adds \vspace*{50\p@} (50pt) above and \vskip 40\p@ (40pt) below. Apr 3, 2023 at 22:34

2 Answers 2

2

John Kormylo has addressed the first part of your question in his answer, so I will answer only the second part.

Firstly, we would like to remove the extra space added by \parskip (which usually should not be changed manually). It can be done with the parskip package, as it is meant just for that, but this package does not patch chapters, so we will to do that ourselves.

With the following code you will get the original vertical spacing before and after sectioning headings and toc entries:

% !TEX TS-program = xelatex
\documentclass{book}
\usepackage{fontspec}


\usepackage[skip=10pt,parfill]{parskip}
\makeatletter
\patchcmd\@makeschapterhead{\parindent\z@}{\parskip\z@\parindent\z@}{}{}
\patchcmd\@makechapterhead{\parindent\z@}{\parskip\z@\parindent\z@}{}{}
\patchcmd\@starttoc{\vskip-\lastskip\vskip\skip@}{}{}{}
\makeatother

\usepackage{titletoc}
\dottedcontents{section}[3.8em]{}{2.3em}{0pc}
\dottedcontents{subsection}[6.1em]{}{3.2em}{0pc}

\newlength\dimone \setlength\dimone{8pt}  % << new length
\newlength\dimtwo \setlength\dimtwo{14pt} % << new length

\usepackage[english]{babel}


\begin{document}
    \tableofcontents
    \chapter{First chapter\the\parskip}
    \section{one}
    \subsection{a}
    \subsection{b}
    \subsection{c}
    \section{two}
    \section{three}
    \section*{Summary}
    \addcontentsline{toc}{section}{Summary}
    \section*{Exercises}
    \addcontentsline{toc}{section}{Exercises}
    \chapter{second chapter}
    \section*{Introduction}
    \addcontentsline{toc}{section}{Introduction}
    \section{one}
    \section{two}
    \section{three}
\end{document}

Now that we have retrieved the original spacing, we can start modifying them to our desire.

% !TEX TS-program = xelatex
\documentclass{book}
\usepackage{fontspec}


\usepackage[skip=10pt,parfill]{parskip}
\makeatletter
\patchcmd\@makeschapterhead{\parindent\z@}{\parskip\z@\parindent\z@}{}{}
\patchcmd\@makechapterhead{\parindent\z@}{\parskip\z@\parindent\z@}{}{}
\patchcmd\@starttoc{\vskip-\lastskip\vskip\skip@}{\vskip-\lastskip\vskip\dimexpr\dimone-\dimtwo\relax}{}{}
\makeatother

\usepackage{titletoc}
\dottedcontents{chapter}[1.5em]{\addvspace\dimtwo}{1em}{0pc}
\dottedcontents{section}[3.8em]{}{2.3em}{0pc}
\dottedcontents{subsection}[6.1em]{}{3.2em}{0pc}


\newlength\dimone \setlength\dimone{8pt}  % << new length
\newlength\dimtwo \setlength\dimtwo{14pt} % << new length

\usepackage[english]{babel}


\begin{document}
    \tableofcontents
    \chapter{First chapter\the\parskip}
    \section{one}
    \subsection{a}
    \subsection{b}
    \subsection{c}
    \section{two}
    \section{three}
    \section*{Summary}
    \addcontentsline{toc}{section}{Summary}
    \section*{Exercises}
    \addcontentsline{toc}{section}{Exercises}
    \chapter{second chapter}
    \section*{Introduction}
    \addcontentsline{toc}{section}{Introduction}
    \section{one}
    \section{two}
    \section{three}
\end{document}
1

The goal here is not to change the spacing, but to verify it. Note that 1em is fontsize dependent, hense \chapskip.

\documentclass{report}
\usepackage{fontspec}
\setlength{\parskip}{10pt}
\setlength{\parindent}{0pt}

\newlength{\chapskip}
\setlength{\chapskip}{1em}

\usepackage[english]{babel}
\begin{document}
\renewcommand{\contentsname}{Contents\hfill\llap{\rule{\linewidth}{0.5pt}\smash{\rule[-40pt]{1pt}{40pt}}}}
\tableofcontents

\chapter{First chapter\hfill\strut\llap{\rule{\linewidth}{0.5pt}\smash{\rule{1pt}{\dimexpr \baselineskip+\chapskip+\parskip}}}}
\section{one\hfill\llap{\rule{0.5\textwidth}{0.5pt}\smash{\rule{1pt}{\dimexpr \baselineskip+\parskip}}}}
\subsection{a\hfill\llap{\rule{0.5\textwidth}{0.5pt}\smash{\rule{1pt}{\dimexpr \baselineskip+\parskip}}}}
\subsection{b}
\subsection{c}
\section{two}
\section{three}
\section*{Summary}
\addcontentsline{toc}{section}{Summary}
\section*{Exercises}
\addcontentsline{toc}{section}{Exercises\hfill\llap{\rule{0.5\textwidth}{0.5pt}}}
\chapter{second chapter\hfill\strut\llap{\rule{\linewidth}{0.5pt}\smash{\rule{1pt}{\dimexpr \baselineskip+\chapskip+\parskip}}}}
\section*{Introduction}
\addcontentsline{toc}{section}{Introduction}
\section{one}
\section{two}
\section{three}

\end{document}

demo

2
  • So there is a length which is equal to 1em and is used as a vskip between chapter entries in the TOC. You defined it to be chapskip, but can you tell me what is its original name and where it is defined?
    – tush
    Apr 17, 2023 at 11:31
  • 1
    \l@chapter from report.cls contains \vskip 1.0em \@plus\p@. I only used \chapskip to make it a fixed size, as opposed to getting larger inside the chapter title. Apr 17, 2023 at 14:42

You must log in to answer this question.

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