Is there a way to make all the table of contents bold by default?
2 Answers
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.
Remarks:
\@dottedtoclineis used for the entries of\section(classreportandbook), and\subsectionto\subparagraph(classesarticle,reportandbook).The standard classes use
\normalfontfor the page number in\@dottedtocline. Thus the nice trick of karlkoller\textbf{\tableofcontentswill 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}
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}
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
- 103
- 271,626
-
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}– karlkoeller Jul 05 '13 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. – Heiko Oberdiek Jul 05 '13 at 14:53 -
-
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}– oakenshield1 Jul 05 '13 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. – Heiko Oberdiek Jul 05 '13 at 15:39
-
@oakenshield1: Unless the table of contents is very short,
\tableofcontents\thispagestyle{fancy}will rather change the page style for the last page. – Heiko Oberdiek Jul 05 '13 at 15:41 -
I'm adding a minimal working example.
main.texfile is the original file as you might guess. – oakenshield1 Jul 11 '13 at 18:26 -
@heiko-oberdiek I've added a MWE. I'll be grateful if you have a look at it. – oakenshield1 Jul 11 '13 at 20:13
-
-
@HeikoOberdiek Worked like a charm. Now is it possible to do the same thing to LOF and LOT. – oakenshield1 Jul 12 '13 at 07:55
-
A very simple manner in a nonconventional way?
\textbf{\tableofcontents}
- 124,410
-
1
-
@blackburn right, but it is really a nonconventional way... I bet this answer will have no upvotes... – karlkoeller Jul 05 '13 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 05 '13 at 11:52
-
1
-
1@blackburn Thanks, but in this way you made me lose the bet...
:-)– karlkoeller Jul 05 '13 at 15:08 -
I've tried this before but it did not work for me. Most probably because of the reason (i.e. fancy headers) I've mentioned in the comments of the answer above. – oakenshield1 Jul 05 '13 at 15:26
-
@oakenshield1 no,
\thispagestyle{fancy}is not the cause. Add an MWE to your question as suggested by Heiko. – karlkoeller Jul 05 '13 at 15:41 -



tocloftpackage. 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