[Tex/LaTex] tocloft conditional spacing

chaptersspacingtable of contentstocloft

This is my first question on stackexchange!

I am using the tocloft package for my thesis and my university requires doublespacing before and after the chapter titles in the ToC, but only if the chapter has sections.

I am thinking that I will require some way to detect if the chapter has sections, or add a newline before the first section in each chapter. Can somebody suggest a way to achieve this?

Best Answer

If I understood your question, you can use the etoolbox package to hook to the \section command to add a vertical spacing in the ToC if the section counter is one:

\documentclass[a4paper]{book}
\usepackage{etoolbox}
\usepackage{tocloft}

\preto\section{%
  \ifnum\value{section}=0\addtocontents{toc}{\vskip10pt}\fi
}

\begin{document}

\tableofcontents

\chapter{A chapter with sections}
\section{Section one one}
\section{Section one two}
\chapter{A chapter without sections}
\chapter{Another chapter with sections}
\section{Section one one}
\section{Section one two}

\end{document}

enter image description here

Related Question