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

Is it possible to create a TOC with section headings in one color and subsection headings in different color.


I am using above lines to create TOC, do I need to use any special package?

share|improve this question
Please don't post an answer in the question. This only confuses people who read the question later on. You should add an answer with this solution (and clearly state that it is just a variation of Stefan's answer). – Caramdir Jan 6 '11 at 19:37
I did not how to post answer back, so I edited the post. I did not know I can answer my own question. I have restored the original post – Aku Jan 6 '11 at 19:39
If you want to, you can still take what you just deleted and post it as an answer. – Hendrik Vogt Jan 7 '11 at 13:54
there is an answer form at the bottom of this page. – Caramdir Jan 7 '11 at 16:21
up vote 6 down vote accepted

You could use the tocloft package for customizing the table of contents.

Without an additional package, you could modify the class macros which are responsible for the table of contents entries, such as \l@section and \l@subsection.

Here is an example for the article class:

\section{Section One}
\subsection{Subsection One}
\subsection{Subsection Two}
\section{Section Two}
\subsection{Subsection One}
\subsection{Subsection Two}

alt text

share|improve this answer
You have forgotten the subsubsection: \renewcommand*{\l@subsubsection}[2]{% \stdl@subsection{\hspace{1cm}\textcolor{TheColorIWant}{#1}}{\textcolor{TheColorI‌​Want}{#2}}} Here we need the \hspace command because \stdl@subsubsection doesn't exist – Álvaro May 18 '12 at 10:12
@Álvaro: I did not forget the subsubsection, as it was asked just for section and subsection, but thanks for the addition. Btw. I converted your answer to a comment, as it's more a comment to the other answer. – Stefan Kottwitz May 18 '12 at 18:04

I've just solve it!


\makeatletter %colorear la tabla de contenidos, extraído de http://tex.stackexchange.com/questions/7526/toc-section-subsection-coloring/56368#56368

The space can be varied with the cftsubsubsecaftersnumb.

share|improve this answer

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.