0

I'm using titlesec to control the appearance of headers (\section and friends) in a larger document, and I'm now investigating tocloft to adjust the appearance of the table of contents (ToC) as well. Since I'd like for the ToC's own heading to use the same style as the remaining sections, I'm loading tocloft with the titles option.

This is working fine, but now I'm finding myself wanting to add some vertical space after the ToC heading (and only after that); for the sake of the argument suppose it's a \bigskip. Usually (i.e. without titles), one could just renew \cftaftertoctitle in an appropriate manner; but with the titles option, tocloft offloads the formatting of ToC heading to LaTeX entirely, so this is a no-op then.

Here's an FMWE (Fairly Minimal Working Example) where the more elaborate \sectionformatting has been replaced by something very simple:

\documentclass{article}
\usepackage{lipsum}
\usepackage{polyglossia}
\usepackage[rigidchapters,explicit]{titlesec}
\usepackage[titles]{tocloft}
\setmainfont{Libertinus Serif}
\titleformat{\section}[block]{\filcenter}{}{0pt}{{\LARGE\bfseries\scshape #1}}[\filcenter]
\setcounter{secnumdepth}{1}
\setcounter{tocdepth}{1}

% ToC customization
\makeatletter
\renewcommand{\cftsecpresnum}{\begin{lrbox}{\@tempboxa}}
\renewcommand{\cftsecaftersnum}{\end{lrbox}}
\makeatother
\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}
\setlength\cftbeforesecskip{0.75em}
\cftsetindents{section}{0pt}{0pt}
\renewcommand{\cftsecfont}{\large\bfseries}
\setlength\cftsecindent{3.3em}
\renewcommand{\cftsecafterpnum}{\hspace*{3.3em}}
\renewcommand{\cftaftertoctitle}{\bigskip}

\begin{document}
    \tableofcontents
    \section{This}
    \lipsum[1]
    \section{That}
    \lipsum[2]
    \section{Something completely different}
    \lipsum[3]
\end{document}

The line that's not doing what it's supposed to here is

\renewcommand{\cftaftertoctitle}{\bigskip}

of course. To illustrate, here's three screenshots (for easy visual comparison, open these in new tabs and switch back and forth between them).

First, with titles in effect, and with the extra \bigskip:

enter image description here

Second, with titles in effect, but without the extra \bigskip:

enter image description here

Third, without titles, and with the extra \bigskip:

enter image description here

And finally, without titles, but without the extra \bigskip:

enter image description here

As you can see, the \bigskip has an effect without titles but not with it. This isn't a surprise, it's how tocloft is intended to work, but --- how do I get some extra vertical space after the ToC's heading if titles is in effect?

BTW: feel free to suggest alternatives to tocloft as well, I'm not too hung up on it and would actually prefer a more usable, less cryptic package (and with a better manual). titlesec, OTOH, I really want to keep.

Thanks!

4
  • So what suggestions do you have to make the package more usable, less cryptic and a better manual? The manual has 13 pages for the general user and 30 pages of documented package code. Commented Feb 23, 2022 at 17:38
  • @PeterWilson More examples, for one, that's the biggest thing. With pretty much anything and everything I've wanted to do I had to google how to do it because I couldn't tell from reading the documentation. I'm sure it's fine for someone who already knows the package well, but not for someone who's unfamiliar with it and who's not a (La)TeX pro at that. YMMV.
    – chsk
    Commented Feb 23, 2022 at 19:30
  • The manual contains approximately 30 examples. How many more do you want? What examples do you think are missing? Commented Feb 25, 2022 at 18:18
  • I'm sorry, I'm not willing to have this discussion. I take it you're the author of tocloft? If so I'm sorry if you felt I was needlessly disparaging your package.
    – chsk
    Commented Feb 26, 2022 at 8:54

1 Answer 1

2

(1) Use \usepackage{tocloft} (no titles)

(2) Format the ToC title exactly like the section titles of the document.

(3) Center the ToC title using \hfill in \cfttoctitlefont and in \cftaftertoctitle

(4) Add vertical space in \cftaftertoctitle

a

\documentclass{article}
\usepackage{lipsum}
\usepackage{polyglossia}
\usepackage[rigidchapters,explicit]{titlesec}

\usepackage{tocloft} % use this <<<<<<<<<<<<<<<<<<<<<<<<<

\setmainfont{Libertinus Serif}
\titleformat{\section}[block]{\filcenter}{}{0pt}{{\LARGE\bfseries\scshape #1}}[\filcenter]
\setcounter{secnumdepth}{1}
\setcounter{tocdepth}{1}

%%% ToC customization
\makeatletter
\renewcommand{\cftsecpresnum}{\begin{lrbox}{\@tempboxa}}
    \renewcommand{\cftsecaftersnum}{\end{lrbox}}
\makeatother
\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}
\setlength\cftbeforesecskip{0.75em}
\cftsetindents{section}{0pt}{0pt}
\renewcommand{\cftsecfont}{\large\bfseries}
\setlength\cftsecindent{3.3em}
\renewcommand{\cftsecafterpnum}{\hspace*{3.3em}}

\renewcommand{\cfttoctitlefont}{\hfill\LARGE\bfseries\scshape} % added <<<<<
\renewcommand{\cftaftertoctitle}{\hfill\vspace{50pt}} % inserting a large space <<<<

\begin{document}
    \tableofcontents
    \section{This}
    \lipsum[1]
    \section{That}
    \lipsum[2]
    \section{Something completely different}
    \lipsum[3]
\end{document}
1
  • Thanks! I'll leave the question open for a little longer before accepting.
    – chsk
    Commented Feb 24, 2022 at 8:00

You must log in to answer this question.

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