[Tex/LaTex] Coloring in Table of contents

colortable of contents

Could someone help me, please ?

I would like coloring dots as Red and Bold (not normal and Black like in the photo).

Any help is highly appreciated.

\documentclass{report}

%%%%% Format font + page + langue
\usepackage[utf8x]{inputenc}
\usepackage[a4paper,top=3cm,bottom=2.5cm,left=2.5cm,right=2cm,marginparwidth=1.75cm,headheight=30pt]{geometry}

\usepackage[french]{babel}
\AddThinSpaceBeforeFootnotes
\FrenchFootnotes
\usepackage[T1]{fontenc}
\setlength{\parindent}{0cm}
\setlength{\parskip}{1em}
\renewcommand{\baselinestretch}{1}
\usepackage[titletoc]{appendix}

%%%%% Table of contents
\setcounter{secnumdepth}{5} % seting level of numbering

\usepackage[colorlinks=true]{hyperref}
\usepackage{tocloft}
\newcommand{\Color}[1]{\hypersetup{linkcolor=#1}\color{#1}}
\renewcommand{\cftchapfont}{\Color{red}\large\bfseries}
\renewcommand{\cftsecfont}{\Color{blue}}
\renewcommand{\cftsubsecfont}{\Color{black}}
\renewcommand{\cftsubsubsecfont}{\Color{green}}
\renewcommand{\cftchappagefont}{\large\bfseries\Color{red}}
\renewcommand{\cftsecpagefont}{\Color{blue}}
\renewcommand{\cftsubsecpagefont}{\Color{black}}
\renewcommand{\cftsubsubsecpagefont}{\Color{green}}
\renewcommand{\cftchapleader}{\Color{red}\cftdotfill{\cftchapdotsep}}
\renewcommand{\cftsecleader}{\Color{blue}\cftdotfill{\cftsecdotsep}}
\renewcommand{\cftsubsecleader}{\Color{black}\cftdotfill{\cftsubsecdotsep}}
\renewcommand{\cftsubsubsecleader}{\Color{green}\cftdotfill{\cftsubsubsecdotsep}}
\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}

\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}

%%%%% Indentfirst
\usepackage{indentfirst}
\setlength{\parindent}{1cm}

\usepackage{libertine} 

\usepackage{lmodern}

\begin{document}
\tableofcontents


\chapter{name of chapter 1}
\section{section 1}
\subsection{subsection 1}
\subsubsection{sub sub section 1}
\section{section 2}

\newpage
\chapter{name of chapter 2}
\section{section 21}
\subsection{sub sec 2}
\section{section 22}


\end{document}

enter image description here

Best Answer

(updated code and screenshot after OP modified his/her own code and query)

I believe you should provide visual clarity to your readers as to (a) which colors are used for sectioning headers within in the ToC and (b) which color is used for hyperlinks.

I thus suggest you load the hyperref package with the option linktocpage, which makes just the pages numbers in the ToC into hypertargets, and (b) use a hyperlink color that's different from any of the colors already used in the ToC red, blue, black, green). Indigo, maybe? Choose a color that's suitable for all links within the document, not just for those shown in the ToC.

  • Basically, you should do everything in your power to help your readers develop a strong Pavlovian reflex: Each time they see an object colored in the "link color", they should want to click on it with their mouse. If there's just one color that shouts "I'm a hyperlink", the Pavlovian reflex will be much stronger.

  • Conversely, if you let lots of different colors (including black in some cases) be compatible with an object being a hyperlink, your readers will learn much more slowly what and where the hypertargets are. Put differently: "If everything is special, then nothing is special". Be very deliberate in how you deploy colors to convey meaning.

Incidentally, the hyperref package should be loaded after the tocloft and xcolor packages.

enter image description here

\documentclass{report}
\usepackage[a4paper,top=3cm,bottom=2.5cm,left=2.5cm,
            right=2cm,marginparwidth=1.75cm,
            headheight=30pt]{geometry}

\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage[svgnames]{xcolor} % for 'DarkGreen' color
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}

\usepackage{tocloft}
\renewcommand{\cftchapfont}{\color{red}\large\bfseries}
\renewcommand{\cftsecfont}{\color{blue}}
\renewcommand{\cftsubsecfont}{\color{black}}
\renewcommand{\cftsubsubsecfont}{\color{DarkGreen}}

\renewcommand{\cftchapleader}{\color{red}     \cftdotfill{\cftsecdotsep}}
\renewcommand{\cftsecleader}{\color{blue}     \cftdotfill{\cftsecdotsep}}
\renewcommand{\cftsubsecleader}{\color{black} \cftdotfill{\cftsecdotsep}}
\renewcommand{\cftsubsubsecleader}{\color{DarkGreen} \cftdotfill{\cftsecdotsep}}

\renewcommand{\cftchappagefont}{\color{red}%\large\bfseries
   }
%\renewcommand{\cftsecpagefont}{\color{blue}}
%\renewcommand{\cftsubsecpagefont}{\color{black}}
%\renewcommand{\cftsubsubsecpagefont}{\color{DarkGreen}}


\usepackage[colorlinks=true,  
       linkcolor=Indigo, % or some other suitable color
       linktocpage]{hyperref}

\begin{document}
\tableofcontents

\chapter{Thoughts}
\section{Hello}
\subsection{World}
\subsubsection{Really!}
\end{document}