7

Is there a way to make all the table of contents bold by default?

  • 2
    Is there any compelling reason why you want to do this? – egreg Jul 05 '13 at 12:01
  • 4
    Because, the institute to which my PhD dissertation should have to be submitted has such outrageously weird thesis writing rules. – oakenshield1 Jul 05 '13 at 14:25
  • 1
    I understand and sympathize with you. – egreg Jul 05 '13 at 14:27
  • If your graduate school is full of prehistoric creatures that force you to put a TOC, LOF and LOT with full bold faces to your document read this carefully. First of all you have to use tocloft package. For the TOC Heiko already gave the answer. For LOF and LOT add his answer the following: \g@addto@macro\cftfigfont{\bfseries} \g@addto@macro\cfttabfont{\bfseries} \g@addto@macro\cftfigpagefont{\bfseries} \g@addto@macro\cfttabpagefont{\bfseries} – oakenshield1 Jul 12 '13 at 08:44

2 Answers2

13

Standard classes

The standard classes article, report, book do not provide an interface to change the font of the entries in the table of contents.

The following example for class article patches the macros that generate the table of contents to add the missing \bfseries.

Result

Remarks:

  • \@dottedtocline is used for the entries of \section (class report and book), and \subsection to \subparagraph (classes article, report and book).

  • The standard classes use \normalfont for the page number in \@dottedtocline. Thus the nice trick of karlkoller \textbf{\tableofcontents will fail for some of the page numbers.

Math

Also math elements in the titles can be made bold in the table of contents, see the comment of blackburn. Remarks:

  • In general, however, this is not a good idea, because some mathematicians use bold to make a vector or tensor. Thus adding bold can change the meaning of the math expressions.

  • On the other hand, mixing different font series in the title does look to good either.

  • And too much math in the titles should be avoided anyway.

Nevertheless here an extended example that sets \boldmath for the document division titles:

\documentclass{article}

\usepackage{etoolbox}

\makeatletter \patchcmd{@dottedtocline}{\leavevmode}{\leavevmode\bfseries\boldmath}{}{} \patchcmd{@dottedtocline}{\normalfont}{\normalfont\bfseries\boldmath}{}{} \patchcmd{\l@part}{\bfseries}{\bfseries\boldmath}{}{} % \patchcmd{\l@chapter}{\bfseries}{\bfseries\boldmath}{}{}% report/book \patchcmd{\l@section}{\bfseries}{\bfseries\boldmath}{}{}% article

\patchcmd{@part}{\bfseries}{\bfseries\boldmath}{}{} \patchcmd{@spart}{\bfseries}{\bfseries\boldmath}{}{} % \patchcmd{@makechapterhead}{\bfseries}{\bfseries\boldmath}{}{}% report/book % \patchcmd{@makeschapterhead}{\bfseries}{\bfseries\boldmath}{}{}% % report/book \patchcmd{\section}{\bfseries}{\bfseries\boldmath}{}{} \patchcmd{\subsection}{\bfseries}{\bfseries\boldmath}{}{} \patchcmd{\subsubsection}{\bfseries}{\bfseries\boldmath}{}{} \patchcmd{\paragraph}{\bfseries}{\bfseries\boldmath}{}{} \patchcmd{\subparagraph}{\bfseries}{\bfseries\boldmath}{}{} \makeatother

\begin{document} \tableofcontents \part{Einstein: $E=mc^2$} \section{Hello world $\alpha+1=\infty$} \subsection{Foo bar $\beta*3=\emptyset$} \subsubsection{Sub sub} \end{document}

Result

Class memoir

Other classes or packages (e.g. titletoc) can provide a more elaborate interface for formatting the table of contents.

Example with class memoir (without \boldmath for simplicity):

\documentclass{memoir}

\addtodef{\cftsectionfont}{}{\bfseries} \addtodef{\cftsubsectionfont}{}{\bfseries} \addtodef{\cftparagraphfont}{}{\bfseries} \addtodef{\cftsubparagraphfont}{}{\bfseries} \addtodef{\cftfigurefont}{}{\bfseries} \addtodef{\cfttablefont}{}{\bfseries}

\addtodef{\cftsectionpagefont}{}{\bfseries} \addtodef{\cftsubsectionpagefont}{}{\bfseries} \addtodef{\cftparagraphpagefont}{}{\bfseries} \addtodef{\cftsubparagraphpagefont}{}{\bfseries} \addtodef{\cftfigurepagefont}{}{\bfseries} \addtodef{\cfttablepagefont}{}{\bfseries}

\renewcommand*{\cftdot}{\bfseries.}

\settocdepth{subsection}

\begin{document} \tableofcontents \part{Part title} \chapter{Introduction} \section{Hello world} \subsection{Foo bar} \subsubsection{Sub sub} \end{document}

Result memoir

Package tocloft

Package tocloft provides similar commands as class memoir (both are written by the same author, Peter Wilson). The missing \addtodef is replaced by LaTeX's \g@addto@macro and the document division names are shorter (e.g. sec instead of section):

\usepackage{tocloft}

\makeatletter \g@addto@macro\cftsecfont{\bfseries} \g@addto@macro\cftsubsecfont{\bfseries} \g@addto@macro\cftparafont{\bfseries} \g@addto@macro\cftsubparafont{\bfseries} \g@addto@macro\cftfigfont{\bfseries} \g@addto@macro\cfttabfont{\bfseries}

\g@addto@macro\cftsecpagefont{\bfseries} \g@addto@macro\cftsubsecpagefont{\bfseries} \g@addto@macro\cftparapagefont{\bfseries} \g@addto@macro\cftsubparapagefont{\bfseries} \g@addto@macro\cftfigpagefont{\bfseries} \g@addto@macro\cfttabpagefont{\bfseries} \makeatother

Heiko Oberdiek
  • 271,626
6

A very simple manner in a nonconventional way?

\textbf{\tableofcontents}
karlkoeller
  • 124,410