5

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

  • Could you post a full, minimal code of what you've tried? – Bernard Aug 4 '18 at 19:47
  • @Bernard I just edited. – Dg PHAM Aug 4 '18 at 19:49
  • 1
    This is not exactly a full code: which document class do you use? Where's \begin{document}, \end{document}? – Bernard Aug 4 '18 at 19:53
  • @Bernard Ok, I posted the full code. – Dg PHAM Aug 4 '18 at 20:01
6

(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}
  • 1
    @marmot - I always appreciate upvotes. :-) (I've upvoted your answer too, by the way.) I fully realize that the OP would like the page numbers to have the same colors as the headers and leaders. However, as I've tried to explain in my answer (and speaking more as a document designer than as a LaTeX programmer), I think it's a highly questionable to let a whole bunch of colors be compatible with the corresponding objects being hypertargets. (Aside: I can't say I "get" what exactly the OP is trying to achieve by making the ToC look like a wildly over-decorated Christmas tree...) – Mico Aug 4 '18 at 21:47
  • 1
    I agree with all your statements. ;-) – marmot Aug 4 '18 at 21:49
4

Thanks for the MWE! You need to use the tricks of this answer, I think.

\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
\setcounter{tocdepth}{5}
\usepackage[colorlinks=true]{hyperref}
\usepackage{tocloft}
\newcommand{\Color}[1]{\hypersetup{linkcolor=#1}\color{#1}}
\renewcommand{\cftchapfont}{\Color{black}\large\bfseries}
\renewcommand{\cftsecfont}{\Color{blue}}
\renewcommand{\cftsubsecfont}{\Color{red}}
\renewcommand{\cftsubsubsecfont}{\Color{green}}
\renewcommand{\cftchappagefont}{\Color{black}}
\renewcommand{\cftsecpagefont}{\Color{blue}}
\renewcommand{\cftsubsecpagefont}{\Color{red}}
\renewcommand{\cftsubsubsecpagefont}{\Color{green}}
\renewcommand{\cftsecleader}{\Color{blue}\cftdotfill{\cftsecdotsep}}
\renewcommand{\cftsubsecleader}{\Color{red}\cftdotfill{\cftsubsecdotsep}}
\renewcommand{\cftsubsubsecleader}{\Color{green}\cftdotfill{\cftsubsubsecdotsep}}
\renewcommand{\cftchapleader}{\large\bfseries\color{red}\cftdotfill{\cftdotsep}}
\renewcommand{\cftchappagefont}{\large\bfseries}
\hypersetup{%
colorlinks=true,% switch on coloured instead of framed links
linkcolor=blue,% main link color (e.g. for the ToC)
filecolor=magenta,% color of links to external files
urlcolor=red,% color to external URLs
}    
\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}

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

\usepackage{libertine} 

\usepackage{lmodern}
%   uncomment these if you want to have the actual chapter font larger
%   \usepackage{titlesec}
%   \titleformat{\chapter}
%   {\normalfont\Huge\bfseries}{\thechapter}{1em}{}    
\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

  • thank you so much. Just a little problem. I add also a subsubsection, but it doesn't appear in the table of contents. Could you solve this ? – Dg PHAM Aug 4 '18 at 20:03
  • 1
    @DgPHAM Just add \setcounter{tocdepth}{5}. I updated the answer accordingly. – marmot Aug 4 '18 at 20:05
  • perfect. Thank you. Could we make the titles of the chapters bigger and bold ? – Dg PHAM Aug 4 '18 at 20:07
  • I need also dots ... connecting between the name of chapter and the Page. Could you help me, please? – Dg PHAM Aug 4 '18 at 20:09
  • as you see in the sample photo in my question, the font of chapters is bigger and bold. I would like to do that in the table of contents. – Dg PHAM Aug 4 '18 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.