4

I'd like to generate a table-of-contents style list of a hand-selected group of figures---that is, a subset of the list captured by \listoffigures.

Although obviously I can open the .lof file itself, I'd like to preserve the dynamic references in my list (in a style with the same kind of results as \ref{}). The .lof file hard-codes the page numbers for the figures.

(The actual use case for this question: I'm assembling a list of the color figures for the print shop, so I'm hand-editing the list to select only the color figures. But I need to make sure the page references stay accurate or they'll print the wrong pages in color.)

Werner
  • 603,163
  • Good question, but perhaps the answer is to create a new environment that, apart from acting as a wrapper for figure, also adds itself to its own 'list of' (see the TeX Blog or the tocloft package). – Sean Allred Sep 23 '13 at 04:37

1 Answers1

5

Here is one option provided via a \colorcaption for each of the coloured figures:

enter image description here

\documentclass{article}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
% See https://tex.stackexchange.com/q/113147/5764
\catcode`\#=12
\newcommand{\colorcaption}{%
  \patchcmd{\@caption}{\par}{%
    \par\addcontentsline{lcf}{#1}%
      {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}}{}{}\caption}%
\catcode`\#=6
\let\@oldstarttoc\@starttoc
\newcommand{\listofcolorfigures}{{%
  \renewcommand{\listfigurename}{List of Coloured Figures}%
  \renewcommand{\@starttoc}[1]{\@oldstarttoc{lcf}}\listoffigures}}
\makeatother
\begin{document}
\tableofcontents
\listoffigures
\listofcolorfigures
\section{A section}
\begin{figure}\caption{A figure}\end{figure}
\begin{figure}\colorcaption{A colour figure}\end{figure}
\begin{figure}\caption{Another figure}\end{figure}
\end{document}

The idea is to create a \colorcaption macro (for coloured figures) that acts the same as \caption, but also inserts a contents line into a new ToC file (with extension .lcf - for list of coloured figures). A companion \listofcolorfigures acts just like \listoffigures, except it calls \@starttoc{lcf} to generate the list of coloured figures.

Patching an argument inside a macro requires some assistance, as provided by Patching arguments inside a macro.

Werner
  • 603,163
  • Can somebody explain how to make this work with labels? I want to use \ref to reference the \listofcolorfigures. – meijuh Mar 22 '14 at 15:58