1

My minimal document looks like this

enter image description here

This colors the numbers in the table of contents, and in the section. How can i color the page number in the table of contents as well?

I tried using tocloft and to redefine \cftXpagefont as it said in the manual, alas this did not change anything. I do not have to use tocloft any package that can solve my problem is more than welcome.

Code

\documentclass{article}
\usepackage{color,tocloft}
\newcommand{\cftXpagefont}{\color{red}}

\renewcommand\thesection{\textcolor{red}{\arabic{section}}}

\begin{document}

\tableofcontents

\section{a} \newpage \section{b} \newpage \section{c}
\end{document}
N3buchadnezzar
  • 11,348
  • 7
  • 55
  • 114

1 Answers1

4

There is no \cftXpagefont defined. Instead, the X refers to the section type in question, like chap (for \chapter), sec (for \section), subsec (for \subsection), etc. So, you can redefine \cftsecpagefont, like below.

enter image description here

\documentclass{article}

\usepackage{xcolor,tocloft}

\renewcommand{\cftsecpagefont}{\bfseries\color{red}}

\renewcommand\thesection{\textcolor{red}{\arabic{section}}}

\begin{document}

\tableofcontents

\section{a} \newpage \section{b} \newpage \section{c}

\end{document}

Note that a redefinition of \thesection will also affect references. If you don't want that you'd have to adjust the formatting in two locations (when setting the sectional title and what it written to the ToC or updated \cftsecpresnum).

Werner
  • 603,163