2

I have two issues in a book I'm preparing:

  1. 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.
  2. 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}
Grant Petty
  • 1,081
  • Did you think of trying with the titletoc package (included in titlesec). It has \tileformat and \contentslabel commands that allow spacing and formatting easily. – Bernard Oct 13 '15 at 15:14
  • the tocloft package has commands for the width of the section numbers -- this is screwed up with \l@... stuff –  Oct 13 '15 at 15:15

1 Answers1

3

You can do this using tocloft itself.

 \cftsetindents{<entry>}{<indent>}{<numwidth>}

So you can do

\cftsetindents{chapter}{0em}{2em}
\cftsetindents{section}{2em}{3em}
\cftsetindents{subsection}{5em}{4.2em}
\cftsetindents{subsubsection}{9.2em}{5em}

Then adjust the values as you wish.

\documentclass{book}

\usepackage[titles]{tocloft}
\renewcommand{\cftpartfont}{\sffamily\bfseries\LARGE}
\renewcommand{\cftchapfont}{\sffamily\bfseries\Large}
\renewcommand{\cftsecfont}{\sffamily\bfseries}
\renewcommand{\cftsubsecfont}{\sffamily\bfseries}
\cftsetindents{chapter}{0em}{2em}
\cftsetindents{section}{2em}{3em}
\cftsetindents{subsection}{5em}{4.2em}
\cftsetindents{subsubsection}{9.2em}{5em}


\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}

enter image description here

  • Alternatively, as per http://tex.stackexchange.com/a/63858/89417 , use \renewcommand\cft<entry>numwidth{<width>} with the abbreviated entry names (chap, sec,subsec). – Marijn Oct 13 '15 at 15:28
  • @Marijn That will mess up the indents. –  Oct 13 '15 at 15:34