I'would like to add different colors in my TOC, depending on the chapter. I've a color for the header, section subsection of each chapter (red chapter one, blue chapter two etc...). With this code I can change colors of chapter name, section and subsection, but this style is the same of all the TOC:





I'm a newbie, I would to exprime like an "if chapter==1 \textcolor{DarkGreen}" "if chapter==2 \textcolor{Red}"... Any ideas?

Thankyou in advance.

  • Just a hint: when entering code in your question, you can indent it with four spaces to get a nice formatting. =) May 19, 2011 at 23:35
  • 2
    Which document class are you using? In your question you talk about changing the color for the chapter entries in the ToC, but your code refers to sections and subsections. Which sectional units must be affected? May 20, 2011 at 0:44

1 Answer 1


You can try the following:


         \color{red}%----- 0 --
    \or  \color{blue}%---- 1 --
    \or  \color{green}%--- 2 --
    \or  \color{cyan}%---- 3 --
    \else \color{black}%-- default



  \chapter{First chapter}
  \section{A section}
  \section{Another section}
  \chapter{Second chapter}
  \section{A section}
  \section{Another section}
  \chapter{First appendix}
  \section{A section}
  \section{Another section}

Resulting in

enter image description here

  • Thankyou very much for the answer! Is that any way to color just the number of the sub section (2.1,2.2)? I cannot find it in the tocloft documentation. Thankyou again!
    – Jake
    May 20, 2011 at 11:48
  • 1
    I found the answer... To color just the numbers of section and Note subsection: \renewcommand{\cftsubsecpresnum}{\toccolor} withot \renewcommand*\cftsubsecfont{\toccolor}
    – Jake
    May 20, 2011 at 11:55
  • Thanks to your answer I've learned how to use \ifcase :). Feb 1, 2012 at 18:42

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.