[Tex/LaTex] ToC: controlling spacing between major headings and subheadings

spacingtable of contentstocloft

So I am attempting to begin early on my thesis, and I am running into some strange TeX problems. I am using 12pt font – important for the spacing commands below. When formatting the ToC we are required to allow double spacing between each major heading (like chapters) but constrain the subheadings within each major heading to single spacing. This results in the following ToC scheme:

    Chapter xxx

    Chapter xxx

      Section xxx
      Section xxx
        Subsection xxx

    Chapter xxx

      Section xxx
      Section xxx

    Chapter xxx

Is there a nice way to produce this style of output? So far the closest I have come is by playing with settings in tocloft. This code comes close but it is not quite what I want:

    \setlength\cftbeforechapskip{0pt}
    \setlength\cftbeforesecskip{-6pt}
    \setlength\cftbeforesubsecskip{-6pt}

    \renewcommand{\cftchapafterpnum}{\vskip 12pt}
    \renewcommand{\cftsecafterpnum}{\vskip 6pt}
    \renewcommand{\cftsubsecafterpnum}{\vskip 6pt}

As you can see it will only produce a half space separation between the major headings and the block of subheadings with a full space between each major heading. Any suggestion would be greatly appreciated! Thanks!

Best Answer

You can do this without packages:

\documentclass[12pt]{book}

\makeatletter
\renewcommand\section{\@startsection {section}{1}{\z@}%
  {-3.5ex \@plus -1ex \@minus -.2ex}%
  {2.3ex \@plus.2ex}%
  {\normalfont\Large\bfseries%
    \ifnum\value{section}=1\relax
      \addtocontents{toc}{\vspace*{12pt}}\fi}%
}

\makeatother

\begin{document}

\tableofcontents
\chapter{Test chapter}
\section{Test section}
\subsection{Test subsection}
\section{Test section}
\chapter{Test chapter}
\chapter{Test chapter}
\section{Test section}
\subsection{Test subsection}
\subsection{Test subsection}
\chapter{Test chapter}
\section{Test section}
\section{Test section}
\subsection{Test subsection}
\subsection{Test subsection}

\end{document}

enter image description here