1

I am trying to control the vertical spacing between entries in the table of contents. Specifically, I need Double space between major section headings and whenever changing levels and single space between like-level sub headings.

\documentclass[10pt,a4paper]{book}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[subfigure]{tocloft} % add nested figures
\usepackage{subfigure}


\renewcommand{\cftchapdotsep}{\cftdotsep}       % Give chapters dots too
\renewcommand{\cftchapfont}{\normalfont}                    % Change to normal font 
\renewcommand{\cftchappagefont}{}               % Change to normal font 

% Center the word 'CONTENTS' over table of contents
\renewcommand{\contentsname}{\hspace*{\fill}\normalfont\normalsize CONTENTS \hspace*{\fill}}  

%add page flush right at top of TOC
\renewcommand{\cftaftertoctitle}{%
    \\[\baselineskip]\mbox{}\hfill{\normalfont Page}}


% My attempt to contol the spacing using tocloft
\renewcommand{\cftchapafterpnum}{\vspace{\cftbeforechapskip}}
%\renewcommand{\cftsecafterpnum}{\vspace{\cftbeforechapskip}}


\begin{document}



\tableofcontents

\chapter{First Chapter}
\chapter{Second Chapter}

\section{First Section}
\section{Second Section}
\subsection{First Subsection}
\subsection{Second Subsection}
\subsubsection{First Subsubsection}
\subsubsection{Second subsubsection}
\chapter{Third Chapter}


\end{document}

Which produces:

enter image description here

I need there to be:

  • Double Spacing between Section 2.2 and Section 2.2.1

This post seems similar, but I cant understand what the command \renewcommand{\cftchapafterpnum}{\vspace{\cftbeforechapskip}} does. A simple trial an error allows me to conclude that the line

\renewcommand{\cftchapafterpnum}{\vspace{\cftbeforechapskip}}

creates an extra space between the Chapter 1 and Section 1.1, but i dont understand why

\renewcommand{\cftsecafterpnum}{\vspace{\cftbeforesecskip}}

does not change the resulting document. I have reviewed the documentation for tocloft, but I cant seem to understand why you chaniging \cftchapafterpnum to \cftsecafterpnum has no effect. I hope I am close.

Thanks in advance!

2
  • Why did you delete your answer? Aug 29 '17 at 13:11
  • @TorbjørnT. because the solution also added a space between sec 2.1 and sec 2.2. I only needed double spacing when section level change
    – dubbbdan
    Aug 30 '17 at 19:03
0

Easily done with etoc in "Another Compatibility Mode" (see its docs).

\documentclass[10pt,a4paper]{book}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[subfigure]{tocloft} % add nested figures
\usepackage{subfigure}


\renewcommand{\cftchapdotsep}{\cftdotsep}       % Give chapters dots too
\renewcommand{\cftchapfont}{\normalfont}                    % Change to normal font 
\renewcommand{\cftchappagefont}{}               % Change to normal font 

% Center the word 'CONTENTS' over table of contents
\renewcommand{\contentsname}{\hspace*{\fill}\normalfont\normalsize CONTENTS \hspace*{\fill}}  

%add page flush right at top of TOC
\renewcommand{\cftaftertoctitle}{%
    \\[\baselineskip]\mbox{}\hfill{\normalfont Page}}


% OP's attempt to control the spacing using tocloft
%\renewcommand{\cftchapafterpnum}{\vspace{\cftbeforechapskip}}
%\renewcommand{\cftsecafterpnum}{\vspace{\cftbeforechapskip}}

\usepackage{etoc}
\newskip\myskip
\myskip\cftbeforechapskip
\cftbeforechapskip0pt\relax

\etocsetstyle{chapter}
  {}
  {\etociffirst{}{\addvspace{\myskip}}}
  {\etocifnumbered
     {\etocsavedchaptertocline{\numberline{\etocnumber}\etocname}{\etocpage}}
     {\etocsavedchaptertocline{\etocname}{\etocpage}}%
  }
  {}

\etocsetstyle{section}
  {\addvspace{\myskip}}%
  {}
  {\etocifnumbered
     {\etocsavedsectiontocline{\numberline{\etocnumber}\etocname}{\etocpage}}
     {\etocsavedsectiontocline{\etocname}{\etocpage}}%
  }
  {\addvspace{\myskip}}

\etocsetstyle{subsection}
  {\addvspace{\myskip}}
  {}
  {\etocifnumbered
     {\etocsavedsubsectiontocline{\numberline{\etocnumber}\etocname}{\etocpage}}
     {\etocsavedsubsectiontocline{\etocname}{\etocpage}}%
  }
  {\addvspace{\myskip}}

\etocsetstyle{subsubsection}
  {\addvspace{\myskip}}
  {}
  {\etocifnumbered
     {\etocsavedsubsubsectiontocline{\numberline{\etocnumber}\etocname}{\etocpage}}
     {\etocsavedsubsubsectiontocline{\etocname}{\etocpage}}%
  }
  {\addvspace{\myskip}}



\begin{document}



\tableofcontents

\chapter{First Chapter}
\section{First Section}
\section{Second Section}
\chapter{Second Chapter}
\section{Third Section}
\section{Fourth Section}
\subsection{First Subsection}
\subsection{Second Subsection}
\subsubsection{First Subsubsection}
\subsubsection{Second subsubsection}
\section{Fifth Section}
\section{Sixth Section}
\chapter{Third Chapter}

\end{document}

enter image description here

The point is that etoc is designed to detect when one goes from subsection to section or from section to chapter etc in the TOC.

For maximal compatibility I have doubled all styles into numbered and un-numbered situations, so that secnumdepth counter can be changed and it still works.

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.