5

I am using article class and tocloft package.

Does anyone know how to put a space (for example of size "22pt") between a ToC section entry and only the first subsection entry in every section.

When I use \setlength\cftbeforesubsecskip{22pt} this puts a space before every subsection entry. I don't want extra space between subsection entires. I only want a space between the section entry and 1st subsection entry (in every section).

What would be useful is a command that changes the space after a section entry, not before. This way I could set the space after a section entry but as far as I know something like \cftAFTERsecskip does not exist.

Does anyone have a suggestion? Thank you!

\documentclass[12pt]{article}
\usepackage{tocloft}

\setlength\cftparskip{0pt}

\setlength\cftbeforesecskip{0pt}

\setlength\cftbeforesubsecskip{22pt}

\setlength\cftaftertoctitleskip{44pt}

\begin{document}
\tableofcontents

\section{Test section one}
\subsection{test section one one}
\subsection{test section one two}
\section{Test section two}
\subsection{test section two one}
\subsection{test section two two}
\clearpage
\section{Test section three}
\subsection{test section three one}
\subsection{test section three two}

\end{document}
1

1 Answer 1

5

One option would be to redefine \subsection as implemented in article.cls. In the redefinition you test for the value of the subsection counter; if the value is greater then one, do nothing; if it's equal to one, add the space to the ToC:

\documentclass[12pt]{article}
\usepackage{tocloft}

\setlength\cftparskip{0pt}
\setlength\cftaftertoctitleskip{44pt}

\makeatletter
\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
  {-3.25ex\@plus -1ex \@minus -.2ex}%
  {1.5ex \@plus .2ex}%
  {\normalfont\large\bfseries%
  \ifnum\value{subsection}>1 \else \addtocontents{toc}{\protect\addvspace{22pt}}\fi}}
\makeatother

\begin{document}
\tableofcontents

\section{Test section one}
\subsection{test section one one}
\subsection{test section one two}
\section{Test section two}
\subsection{test section two one}
\subsection{test section two two}
\clearpage
\section{Test section three}
\subsection{test section three one}
\subsection{test section three two}

\end{document}

enter image description here

Patching the \subsection command with the help of \patchcmd from the etoolbox package simplifies the code:

\documentclass[12pt]{article}
\usepackage{tocloft}
\usepackage{etoolbox}

\setlength\cftparskip{0pt}
\setlength\cftaftertoctitleskip{44pt}

\patchcmd{\subsection}{\bfseries}%
  {\ifnum\value{subsection}>1 \else \addtocontents{toc}{\protect\addvspace{22pt}}\fi}{}{}

\begin{document}
\tableofcontents

\section{Test section one}
\subsection{test section one one}
\subsection{test section one two}
\section{Test section two}
\subsection{test section two one}
\subsection{test section two two}
\clearpage
\section{Test section three}
\subsection{test section three one}
\subsection{test section three two}

\end{document}

You must log in to answer this question.

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