The tocloft package implements a number of commands to customize the table of contents, list of figures and list of tables. One of these commands provided by the package adds whitespace before entries. This is particularly neat for short documents, but might also improve the readability in longer content lists. However, it has its limitations and I will therefore introduce a more flexible approach allowing conditional addition of whitespace.



Lets assume we have the following chapters and sections in our thesis.

\documentclass[12pt]{report} \begin{document} \tableofcontents \chapter{Introduction} \chapter{Main chapter one} \section{Background} \section{Methods} \section{Results} \section{Conclusion} \chapter{Main chapter two} \section{Background} \section{Methods} \section{Results} \section{Conclusion} \chapter{Main chapter three} \section{Background} \section{Methods} \section{Results} \section{Conclusion} \chapter{Conclusion} \end{document}



Let’s add some whitespace between sections to spread the contents more evenly over the entire page. Here, I use \cftbeforeXskip of the tocloft package to add some whitespace before every section entry. X is replaced by chap , sec , etc. (see documentation).

\usepackage{tocloft} \setlength{\cftbeforesecskip}{10pt}



Frankly, it doesn’t look great. Better would be to add whitespace after chapter entries and to keep the sections together. \cftXafterpnum does the trick.

\usepackage{tocloft} \renewcommand{\cftchapafterpnum}{\vspace{10pt}}



Much better, but now we get extra whitespace after “Introduction” because this chapter has no sections. Without sections, the whitespace after the previous and before the next chapter creates an uneven picture.

The solution is to “conditionally” add whitespace depending on whether a chapter sections or not. This requires the etoolbox package. It implements functionality to “append” and “prepend” code to other commands. In the example below, I use the “prepend”-command: \preto . Similarly, \appto can be used to “append” something. See the package documentation for more details.

We would like to have additional whitespace before the first section of a chapter. Therefore, before starting a new section we check if the section counter has been reset to 0. If so, we add whitespace to the table of contents using \addtocontents .

\usepackage{etoolbox} \preto\section{% \ifnum\value{section}=0\addtocontents{toc}{\vskip10pt}\fi }



Using the same idea, we could add chapter headings between list of figure entires for a better separation.

\usepackage{etoolbox, tocloft} \preto\figure{% \ifnum\value{figure}=0\addtocontents{lof}{{\bfseries Chapter \thechapter\vskip10pt}}\fi }

Note: Without loading tocloft chapter headings are indented except for the first.



Before:



After:



And possibly lots of other cool stuff. Let me know your ideas below! 🙂

Share this: Twitter

Facebook

Reddit

LinkedIn

Skype

Email



Like this: Like Loading...