7

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

4
  • 2
    Is there any compelling reason why you want to do this?
    – egreg
    Jul 5, 2013 at 12:01
  • 4
    Because, the institute to which my PhD dissertation should have to be submitted has such outrageously weird thesis writing rules. Jul 5, 2013 at 14:25
  • 1
    I understand and sympathize with you.
    – egreg
    Jul 5, 2013 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} Jul 12, 2013 at 8:44

2 Answers 2

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
11
  • I was waiting for a nice answer from you, thanks. Anyway, I have a doubt: is there anything that one can do in this case? \section{The \texttt{\#include} directive} Jul 5, 2013 at 14:49
  • @karlkoeller: Using a typewriter font family that provides a bold variant helps. Instead of the Computer Modern fonts, the Latin modern fonts (\usepackage{lmodern}) can be used, for example. Jul 5, 2013 at 14:53
  • Thanks very much, Heiko. This is just what I wanted to know. Jul 5, 2013 at 15:06
  • Sorry but it did not work for me. I guess it is because of fancyhdr package which i have to use for page numbering: \tableofcontents\thispagestyle{fancy} Jul 5, 2013 at 15:28
  • @oakenshield1: Please edit your question to add a minimal working example (MWE). Also add a more descriptive problem description. "Does not work" can be anything from a serious error message to a forgotten element that is not bold. Jul 5, 2013 at 15:39
6

A very simple manner in a nonconventional way?

\textbf{\tableofcontents}
8
  • 1
    Also add \boldmath for making math bold.
    – Jagath
    Jul 5, 2013 at 11:34
  • @blackburn right, but it is really a nonconventional way... I bet this answer will have no upvotes... Jul 5, 2013 at 11:46
  • I strongly feel, this is one of the many possible answer. I am giving an upvote, since this answer surely helps a beginner.
    – Jagath
    Jul 5, 2013 at 11:52
  • 1
    Unfortunately, this doesn't use boldface for the page numbers. Jul 5, 2013 at 13:55
  • 1
    @blackburn Thanks, but in this way you made me lose the bet... :-) Jul 5, 2013 at 15:08

You must log in to answer this question.

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