4

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?

3
  • Welcome to TeX.sx! Am I correct that there should be additional vertical space before/after chapter titles in the table of contents? (You added the tocloft tag, but did not mention the ToC in your actual question.)
    – lockstep
    Nov 11, 2011 at 19:10
  • BTW, you don't have to sign with your name since it automatically appears in the lower right corner of your post.
    – lockstep
    Nov 11, 2011 at 19:11
  • Thanks lockstep! There should be additional space after the chapter title if the chapter has sections within it. The section titles themselves are single spaced. I have \setlength{\cftbeforechapskip}{\baselineskip} but this only helps me in adding space before section titles. Nov 11, 2011 at 19:26

1 Answer 1

5

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

6
  • @Nikhil Gupta: Hmm... now that I see my answer, this surely is not what you need, or is it? Nov 11, 2011 at 19:31
  • However, the correct code is ` \preto\section{% \ifnum\value{section}=1\addtocontents{toc}{\vskip10pt}\fi }` Nov 11, 2011 at 19:59
  • @NikhilGupta: are you sure? If so, then I didn't fully understand your question. Nov 11, 2011 at 20:01
  • In the version that you composed, you were adding extra space in the else condition so it would add space before all sections except the first. That's the only modification I made. Nov 11, 2011 at 20:05
  • @NikhilGupta: maybe I am misunderstanding you, but the code I posted produces the result illustrated in the attached image; i.e., extra space before the first section. Nov 11, 2011 at 20:09

You must log in to answer this question.

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