[Tex/LaTex] How to change the font of page numbers in TOC LOT LOF without “tocloft”

fontspage-numberingtable of contents

It can be easily done with tocloft, however, as there are already many settings for the whole document, using it caused the changing of spacing, and some conflicts with other packages, etc, compared to the original style for book class.

enter image description here

So how to change the font of page numbers for chapters, sections , tabs and figs.. in front matter, without use of tocloft package.

Edit 1:

Using tocloft

\usepackage[ ]{tocloft}
\renewcommand{\cftchappagefont}{\bfseries \sffamily}
\renewcommand{\cftsecpagefont}{ \sffamily}
\renewcommand{\cftsubsecpagefont}{ \sffamily}  
\renewcommand{\cftsubsubsecpagefont}{ \sffamily}
\renewcommand{\cftfigpagefont}{ \sffamily}
\renewcommand{\cfttabpagefont}{ \sffamily}

The error:

enter image description here

The following commands have been commented:

% \setcounter{tocdepth}{3}  
% \setcounter{secnumdepth}{3}

I dont know if tocloft is conflicted with \usepackage[nottoc]{tocbibind}.

Besides, the spacing between entries in TOC, LOT, LOF are enlarged, and the blank pages are also removed which is created by default in book class.

Best Answer

The formatting of these lines is controlled by macros \l@chapter \l@section etc. In book class, \l@chapter has a custom definition but all the rest are defined in terms of \@dottedcontentsline so it is enough to redefine just those two commands to use a custom font. Here I use italic and colour to highlight the effect.

enter image description here

\documentclass{book}

\usepackage{color}

\makeatletter
\let\oldl@chapter\l@chapter
\def\l@chapter#1#2{\oldl@chapter{#1}{\textcolor{red}{\itshape#2}}}

\let\old@dottedcontentsline\@dottedtocline
\def\@dottedtocline#1#2#3#4#5{%
\old@dottedcontentsline{#1}{#2}{#3}{#4}{{\textcolor{green}{\itshape#5}}}}



\makeatother
\begin{document}
\tableofcontents
\listoffigures
\chapter{bbaa}

\section{zax}

aaa
\begin{figure}\caption{fff}\end{figure}
\begin{figure}\caption{ggg}\end{figure}


\section{xxzz}
bb
\chapter{bbaa}

\end{document}
Related Question