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 am writing a document using the book class, and I use tocloft in order to customize the appearance of my ToC. So far, the package did a great job for most customizations, except for one thing: I am trying to highlight ToC entries for the book parts (created with \part) with a grey box. Is there any way to do that?

I found \colorbox and soul as solutions for highlighting text in general, but I do not have an idea how to apply them to the ToC entries for parts.

share|improve this question
Thank you very much for the suggestions! I already knew the first one, but it does not really help me as I am trying to highlight the background of a text, not the text itself. However, the second solution looks promising. Maybe I end up switching to titletoc. Just wondered whether there was a way doing it with tocloft. – elsvene Jul 9 '11 at 11:37
up vote 7 down vote accepted

Here's a solution using tikz and tocloft. It places hidden nodes in the tocloft formatting commands for part and then uses the overlay function of tikz to draw the box.

% command to make a hidden node
    \tikz[remember picture] \node[minimum size=0pt,inner sep=0pt,outer sep=5pt] (#1) {};}
% create a node at the beginning of the part entry
% create a node at the end of the part page number and draw the gray box
  \hnode{P2}\tikz[remember picture,overlay] 
  \draw (P1.north west)  [line width={25pt}, gray,opacity=.2] -- (P2.north east);}

\part{First part}
\chapter{A chapter}
\section{A section}
\part{Second Part}
\chapter{Another chapter}

output of code

Note that you need to compile your document twice to have the overlay align correctly.

share|improve this answer
This one works like a charm! Thank you very much! – elsvene Jul 18 '11 at 18:45

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.