[Tex/LaTex] How to change the color of TOC part font using tocloft

colorfontstable of contentstocloft

I have customised my toc using tocloft for everything from chapter down to subsection, but I cant work out how to change the color of the part font, how do you renew this command? I have read the tocloft documentation and can't find anything. Thanks for any help!

MWE:

\documentclass[a4paper, 12pt, twopage]{scrreprt}
\usepackage[titles]{tocloft}
\usepackage{color}
\definecolor{RoyalRed}{RGB}{157,16, 45}
\newcommand{\partfont}{\renewcommand\cftpartfont{\color{RoyalRed}}}

\newenvironment{MainTOC}{\partfont}

\begin{document}
\begin{MainTOC}
\tableofcontents
\end{MainTOC}

\part{first part}
\chapter{First chapter}
\part{second part}
\chapter{second chapter}
\end{document}

Best Answer

You can use \cftpartfont for changing the font of part title and its number and cftpartpagefont for changing the font for page.

\documentclass{book}
\usepackage{xcolor}

\usepackage{tocloft}
\renewcommand\cftpartfont{\color{olive}}
\renewcommand\cftpartpagefont{\color{olive}}

\begin{document}
  \tableofcontents
  \part{A part}
  \chapter{a chapter}
  \part{another part}
\end{document}

enter image description here