\titletoc, formatting \dottedcontents: color of chapter number

After much playing around I have encountered an issue with only setting the \thechapter number in color, when using titletoc and \dottedcontents. I achieve the following, but as you can tell the chapter number is repeated. Is there a way to call onto \thecontentslabel in such a way as to avoid this?

\documentclass{book}
\usepackage[newparttoc]{titlesec}

\usepackage[dvipsnames]{xcolor}
\definecolor{myred}{RGB}{239, 0, 0}
\definecolor{myblue}{RGB}{0,0,200}
\PassOptionsToPackage{pdfpages}{xcolor}

\usepackage{titletoc}
\titlecontents{part}[0pt]{\large\bfseries}
{\contentslabel[\color{myred} \thecontentslabel]{1.5em}}
{}
{\hfill\contentspage}

\dottedcontents{chapter}[2em]{\large\bfseries}
{\contentslabel[{\color{myblue}\thecontentslabel}]{2em}}{}

\begin{document}
\tableofcontents
\part{Trial name of Part}
this is a blind text

\chapter{Trial chapter}
this is more blind text

\section{Trial section}
\end{document}


You had a misuse of \dottedcontents , with same syntax as \titlecontents. Here is a solution with the latter command:

\documentclass{book}
\usepackage[showframe]{geometry}

\usepackage[newparttoc] {titlesec}
\titleformat{\part}[display]
{\Huge\fontsize{30pt}{60pt}\filcenter}{\partname{} \color{myred}\thepart}{0em}
\makeatother
\usepackage{titletoc}
\usepackage[dvipsnames, pdfpages]{xcolor}
\definecolor{myred}{RGB}{239, 0, 0}
\definecolor{myblue}{RGB}{0,0,200}
\titlecontents{part}[2.2em]{\Large\bfseries}
{\contentslabel[\color{myred} \thecontentslabel]{1.35em}}
{}
%
\titlecontents{chapter}[2.2em]{\large\bfseries}
{\contentslabel[{\color{myblue}\thecontentslabel}]{1em}}
{}
%
\titlecontents{section}[2.83em]{}
{\contentslabel[{\thecontentslabel}]{1.9em}}
{}

\begin{document}\setcounter{part}{3}
\tableofcontents
\part{Trial name of Part}
this is a blind text

\chapter{Trial chapter}
this is more blind text

\section{Trial section}

\end{document} [1.5em]


• Thak you; Is there a syntax that would fix my issue with \dottedcontents? I am trying to understand why it would not be possible to just change the number and leave everything else as is – Gmaster Mar 11 '18 at 21:08
• Unfortunately, dottedcontents has no way to format the label. You only give can enter commands for global formatting of entries (this means that if you type \color{blue}, the label and the section title will be blue). – Bernard Mar 12 '18 at 18:45
• Thank you for that. So to clarify, the \thecontentslabel then refers to the entire entry, rather than just the \chapter number? – Gmaster Mar 12 '18 at 19:50
• Not at all. It contains just the chapter (or section or…) number. The first mandatory argument of \dottedcontents as well as \titlecontents is for the global formatting. But the second mandatory argument of \dottedcontents is the label width, whereas the second of \titlecontents is for the formatting of the entry (for numbered entries),in which you can use the \contentslabel command to format the label, the rest acting on the title. The third argument is for the formatting of unnumbered chapters, sections, &c. – Bernard Mar 12 '18 at 20:35