[Tex/LaTex] How to control spacing in toc for different sections

spacingtable of contents

I need to have a TOC that has double space between Chapter titles but single space between sections and subsections. I know there are several related questions on this matter, but the difference is that when using some of the suggested solutions like \setlength{\cftbeforesecskip}{-2pt} or \renewcommand\cftchapafterpnum{\vspace{}} that changes the spacing before or after the section or subsection, and if the title in question is one-line long is fine, but if its a long three lines title of a section then, it gives very irregular spacing, with the desired space above the section title, and then what looks like one half spacing and again single spaced after the page number.
Another solution I have tried is within the actual text use something like \section[\singlespacing{\noindent Long title}]{Long title}but then although I get single spaced lines in the TOC, I also get some undesired vertical space between the section number and the beginning of the section title. Is there any way of uniformly changing the spacing in the TOC by hierarchical sections, or avoid the extra vertical space in my second approach? Also, it is worth mentioning that I am loading the setspacepackage and using \onehalfspacing on the preamble of my document, since the main body of it should be one-half spaced. Thanks a lot,
Here is how it looks what I have:

\documentclass[12pt,reqno]{report}
\usepackage[titles]{tocloft}
\setlength{\cftbeforesecskip}{-2.5pt}
\setlength{\cftbeforesubsecskip}{-2.5pt}
\usepackage{setspace}
\onehalfspacing
\usepackage{blindtext}
\begin{document}
\tableofcontents
\newpage
\chapter{this is a really really long title that someone else wrote for all the penguins in the world}
\section{this is a really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really long title having more than three lines of text to appear on the toc.}
\subsection{this is a really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really long title having more than three lines of text to appear on the toc.}
\blinddocument
\blinddocument
\blinddocument
\blinddocument
\end{document}

On this MWE I show one of the options I tried. I hope someone can comment on this. Thanks.

Best Answer

You can hook into \cftchapafterpnum for adding some vertical space after a chapter title in the table of contents.

\documentclass[12pt,reqno]{report}
\usepackage[titles]{tocloft}
\usepackage{blindtext}

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

\begin{document}
\tableofcontents
\newpage
\chapter{this is a really really long title that someone else wrote for all the penguins in the world}
\section{this is a really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really long title having more than three lines of text to appear on the toc.}
\subsection{this is a really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really long title having more than three lines of text to appear on the toc.}
\blinddocument
\blinddocument
\blinddocument
\blinddocument
\end{document}

enter image description here

However, long titles have nothing to do with the problem; you seem to be loading setspace with \onehalfspacing, probably to comply with silly requirements by your institution (if not, just use standard spacing, you'll leave happier).

Just issue \singlespacing when doing the table of contents.

\documentclass[12pt,reqno]{report}
\usepackage[titles]{tocloft}
\usepackage{setspace}
\usepackage{blindtext}

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

\onehalfspacing

\begin{document}

\begingroup\singlespacing
\tableofcontents
\endgroup

\chapter{this is a really really long title that someone else wrote 
for all the penguins in the world}
\section{this is a really really really really really really really
really really long title having more than three lines of text to appear on the toc.}
\subsection{this is a really really really really really really really
really really really long title having more than three lines of text to appear on the toc.}

\blinddocument

\end{document}

enter image description here

Related Question