TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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 have a command that prints an image and will be used inside a certain environment.

First I run a test if the file exists and is a valid image file (see this question for the definition of \imagetest).
If it is ok then the image is just printed, otherwise I print a box with an informative message.

    {% If it is a valid image do:


    {% If it isn't a valid image do:

        %TODO: Make the entry in the \listof...s red
            {Image #1 missing}}


So far it works ok, but I would like to also print the caption red _in the list of ...
What I found is that with


I can change the appearance of the caption, but only that at the current place in the document. If I do

\DeclareCaptionListFormat{mystyle}{\textcolor{red}{#1 #2}}

and then


It actually changes the \listof, but only the reference number gets colored.

So the question is: How can I color the list entry of such a floating environment?
Actually I'd also accept a suitable other way to highlight such an entry

share|improve this question
up vote 5 down vote accepted

Your \DeclareCaptionListFormat code makes LaTeX write

\contentsline {figure}{\numberline {\textcolor{red}{1}}{\ignorespaces This will be red\relax }}{1}

in the .lof file. Using \color{red}#1#2 wouldn't help, because the argument of \numberline is typeset in a group, so the color setting doesn't propagate to the caption text.

One can use a trick:



\DeclareCaptionListFormat{mystyle}{\makered#1 #2}
\caption{This will be red}
\caption{This will be black}

Thus the first caption will cause writing

\contentsline {figure}{\numberline {\makered 1}{\ignorespaces This will be red\relax }}{1}

in the .lof file. When LaTeX typesets it, \makered becomes \makeredaux that prints the number in red, followed by \aftergroup\makeredaux that will be executed when the \numberline group is finished, that is, when LaTeX is typesetting the caption text (in the list of figures).

enter image description here

(Note: in the image the figures are at the top, because no positioning argument has been specified in this example document.)

share|improve this answer
Thank you, works perfectly. And I even think I understand what's working ;-) – uli_1973 Feb 21 '13 at 0:13

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.