Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
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 '11 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 '11 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. –  Nikhil Gupta Nov 11 '11 at 19:26
add comment

1 Answer

up vote 4 down vote accepted

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

share|improve this answer
    
@Nikhil Gupta: Hmm... now that I see my answer, this surely is not what you need, or is it? –  Gonzalo Medina Nov 11 '11 at 19:31
    
Thanks Gonzalo! That's exactly what I needed. –  Nikhil Gupta Nov 11 '11 at 19:33
    
However, the correct code is ` \preto\section{% \ifnum\value{section}=1\addtocontents{toc}{\vskip10pt}\fi }` –  Nikhil Gupta Nov 11 '11 at 19:59
    
@NikhilGupta: are you sure? If so, then I didn't fully understand your question. –  Gonzalo Medina Nov 11 '11 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. –  Nikhil Gupta Nov 11 '11 at 20:05
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.