I have two issues in a book I'm preparing:
- In the case of double-double-digit section numbers, the TOC doesn't
leave enough space between the numbers and the title. In fact, they
can overlap. - I want to change the font of the entries in the TOC.
The first problem can be solved using the following:
\makeatletter
\renewcommand{\l@chapter}{\@dottedtocline{1}{1.5em}{2.6em}}
\renewcommand{\l@section}{\@dottedtocline{1}{1.5em}{2.6em}}
\renewcommand{\l@subsection}{\@dottedtocline{2}{4.0em}{3.6em}}
\renewcommand{\l@subsubsection}{\@dottedtocline{3}{7.4em}{4.5em}}
\makeatother
The second problem can be solved with
\usepackage[titles]{tocloft}
\renewcommand{\cftpartfont}{\sffamily\bfseries\LARGE}
\renewcommand{\cftchapfont}{\sffamily\bfseries\Large}
\renewcommand{\cftsecfont}{\sffamily\bfseries}
\renewcommand{\cftsubsecfont}{\sffamily\bfseries}
For reasons I don't understand, these two solutions aren't compatible — if I uncomment the lines that address the spacing issue, they apparently disable the tocloft statements that modify the font.
How do I achieve both things in the same document?
Below is an MWE:
\documentclass{book}
\usepackage[titles]{tocloft}
% The following lines, when uncommented, correct the
% shortage of space following section numbers
% in the Table of Contents.
\makeatletter
\renewcommand{\l@chapter}{\@dottedtocline{1}{1.5em}{2.6em}}
\renewcommand{\l@section}{\@dottedtocline{1}{1.5em}{2.6em}}
\renewcommand{\l@subsection}{\@dottedtocline{2}{4.0em}{3.6em}}
\renewcommand{\l@subsubsection}{\@dottedtocline{3}{7.4em}{4.5em}}
\makeatother
% The following lines, when uncommented, change the font used
% by section titles in the Table of Contents.
% However they are somehow disabled by the lines above.
\renewcommand{\cftpartfont}{\sffamily\bfseries\LARGE}
\renewcommand{\cftchapfont}{\sffamily\bfseries\Large}
\renewcommand{\cftsecfont}{\sffamily\bfseries}
\renewcommand{\cftsubsecfont}{\sffamily\bfseries}
\begin{document}
\tableofcontents
\chapter{Chapter}
\chapter{Chapter}
\setcounter{chapter}{10}
\chapter{Chapter}
\section{Section}
\section{Section}
\setcounter{section}{10}
\section{Section}
\section{Section}
\subsection{Subsection}
\subsection{Subsection}
\setcounter{subsection}{10}
\subsection{Subsection}
\subsection{Subsection}
\chapter{Chapter}
\end{document}
Best Answer
You can do this using
tocloft
itself.So you can do
Then adjust the values as you wish.