TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Just a hint: when entering code in your question, you can indent it with four spaces to get a nice formatting. =) – Paulo Cereda May 19 '11 at 23:35
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? – Gonzalo Medina May 20 '11 at 0:44

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

share|improve this answer
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 '11 at 11:48
I found the answer... To color just the numbers of section and Note subsection: \renewcommand{\cftsubsecpresnum}{\toccolor} withot \renewcommand*\cftsubsecfont{\toccolor} – Jake May 20 '11 at 11:55
Thanks to your answer I've learned how to use \ifcase :). – Grzegorz Wierzowiecki Feb 1 '12 at 18:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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