How can I make page numbers red in table of contents? I have
colorlinks=true
,linkcolor=blue
, so standard internal links are blue;linctoc=all
, so both table of contents entry names and page numbers are links (the dots themselves are not);\hypersetup{linkcolor=black}
in the group generating the table of contents, so the links in the table of contents are black instead of blue everywhere else.
Finally, I hoped to change the color of the page numbers (to red, for example) in table of contents independently from the entry name color (black in this instace). As a start, I added \renewcommand{\cftsecpagefont}{\color{red}}
to change the page numbers of sections, but it is ignored.
(It is also ignored when placed inside the group generating the table of contents. Furthermore, it is ignored even if \hypersetup{linkcolor=black}
is removed from the group.
Conversely, \renewcommand{\cftsecpagefont}{\bfseries}
has the intended effect...)
\documentclass{book}
\usepackage{tocloft}
\usepackage{titlesec}
\usepackage{xcolor}
\usepackage[colorlinks=true, linkcolor=blue, hypertexnames=false, linktoc=all]{hyperref} % blue internal links for document; in TOC, entry name and page nr are links
\renewcommand{\cftsecpagefont}{\color{red}} % does not work
\begin{document}
{\hypersetup{linkcolor=black} % black links for table of contents (but you may comment this out, red color still not added)
\tableofcontents}
\chapter{Example chapter}
\section{Example section}
\subsection{Example subsection}
This is some text.
\end{document}
The question Change the page numbers in the Table of Contents to red by A H is not a duplicate: there linktoc=all
is replaced with linktocpage
. This removes links from entry names which is not desired.