My actual situation
I set (with the following commands) that in the table of contents each chapter
element is represented with the color steelblue
, while sections and subsections are represented in black
.
\RequirePackage{titletoc}
\setcounter{tocdepth}{2}
\titlecontents{chapter}[0cm]
{\addvspace{14pt}\large\sffamily\bfseries}
{\color{steelblue}\contentslabel[\Large\thecontentslabel]{1.25cm}}{}
{\color{steelblue}\normalsize\sffamily\bfseries
\;\titlerule*[.5pc]{.}\;\thecontentspage}
\titlecontents{section}[0cm]
{\addvspace{6pt}\sffamily\bfseries}
{\contentslabel[\thecontentslabel]{1.25cm}}{}
{\sffamily\hfill\color{black}\thecontentspage}[]
The problem is that my toc does not create any links to the referenced pages.
Therefore, in order to generate a toc with the links, I thought to add the hyperref
package
The issue
After adding the package named above, I cannot determine how to color the chapters of the toc (steelblue
) differently from all other components.
I have found a workaround, which I mark in the following code, but I am not satisfied with it as the clickable reference is only placed on the page number (and not on the chapter/section/...
"tag")
\hypersetup{
bookmarksnumbered=true,
bookmarksopen=true,
bookmarksopenlevel=3,
colorlinks,
breaklinks,
linkcolor=blue,
citecolor=blue,
filecolor=black,
linktocpage=true,
}
My goal
I am trying to figure out how to change just the color of the chapter links in the toc of my project.
Unfortunately, just putting colorlinks=true
in the hypersetup
everything becomes monochrome (which is red by default, but even changing it with linkcolor
the issue is still the same).
MWE
main.tex
\documentclass{mybook}
\renewcommand{\familydefault}{\sfdefault}
\setlength{\parindent}{0pt}
\begin{document}
\tableofcontents
%---------------------------------------------------------------------------
% Chapters
%---------------------------------------------------------------------------
\chapter{Chapter 1}
\section{Section 1.1}
\section{Section 1.2}
\chapter{Chapter 2}
\end{document}
mybook.cls
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{mybook}
\LoadClass[11pt]{book}
% Colors
%--------------------------------------------------------------------------
\RequirePackage{xcolor}
\definecolor{steelblue}{RGB}{70,130,180}
% Table of contents styling
%--------------------------------------------------------------------------
\RequirePackage{titletoc}
\setcounter{tocdepth}{2}
\titlecontents{chapter}[0cm]
{\addvspace{14pt}\large\sffamily\bfseries}
{\color{steelblue}\contentslabel[\Large\thecontentslabel]{1.25cm}}{}
{\color{steelblue}\normalsize\sffamily\bfseries
\;\titlerule*[.5pc]{.}\;\thecontentspage}
\titlecontents{section}[0cm]
{\addvspace{6pt}\sffamily\bfseries}
{\contentslabel[\thecontentslabel]{1.25cm}}{}
{\sffamily\hfill\color{black}\thecontentspage}[]