Take the 2-minute tour ×
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.

I'm writing a paper where I'm trying to repurpose the list of figures as a figure legends section. I'd like each figure to have something like "Figure X: Title" at the bottom, with list of figures entries containing "Figure X: Title", followed by the legend on a new line.

I've almost got what I want using the tocloft package with the following:

\documentclass{article}

\usepackage[demo]{graphicx}
\usepackage{lipsum}

\usepackage[titles]{tocloft}
\addtocontents{lof}{\cftpagenumbersoff{figure}}
\renewcommand\listfigurename{Figure Legends}
\renewcommand\cftfigpresnum{\bfseries Figure }
\renewcommand\cftfigaftersnum{\bfseries :}
\renewcommand\cftfigaftersnumb{\\}
\renewcommand{\cftdotsep}{\cftnodots}
\setlength\cftbeforefigskip{12pt}

\begin{document}

\lipsum[1]
\begin{figure}[ht]
  \centering \includegraphics{image1}
  \caption[Normally a much longer legend for the first figure.]{Title for first fig}
\end{figure}
\lipsum[2]

\clearpage
\listoffigures

\end{document}

Note that I've put the legend in the "short" caption and the title in the "long" caption. The one thing I haven't managed to figure out is how to have both the "short" and "long" captions in the list of figures.

I considered using the cftXaftersnum command to include the short caption as a variable, but I'm not sure how to go about doing this.

UPDATE:

The answer is brilliant, but I neglected to point out one additional requirement: I need doublecaption to cooperate with subfigures. I have one figure with two subfigures, and the counter gets double-incremented. Here's an example using the solution:

\documentclass{article}

\usepackage{amsmath}
\usepackage[demo]{graphicx}
\usepackage{lipsum}

\usepackage{subcaption}

\usepackage[titles]{tocloft}
\addtocontents{lof}{\cftpagenumbersoff{figure}}
\renewcommand\listfigurename{Figure Legends}
\renewcommand\cftfigpresnum{\bfseries Figure }
\renewcommand\cftfigaftersnum{\bfseries : }
\renewcommand{\cftdotsep}{\cftnodots}
\setlength\cftbeforefigskip{12pt}

\newlength\mylength
\settowidth\mylength{\cftfigpresnum}
\addtolength\cftfignumwidth{\mylength}

\makeatletter
\def\doublecaption{%
  \ifx\@captype\@undefined
    \@latex@error{\noexpand\caption outside float}\@ehd
    \expandafter\@gobble
  \else
    \refstepcounter\@captype
    \expandafter\@firstofone
  \fi
  {\@dblarg{\@doublecaption\@captype}}%
}
\long\def\@doublecaption#1[#2]#3{%
  \par
  \addcontentsline{\csname ext@#1\endcsname}{#1}%
    {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #3\newline#2}}%
  \begingroup
    \@parboxrestore
    \if@minipage
      \@setminipage
    \fi
    \normalsize
    \@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
  \endgroup}
\makeatother


\begin{document}

\lipsum[1]
\begin{figure}[ht]
  \centering \includegraphics{image1}
  \doublecaption[Normally a much longer legend for the first figure.]{Title for first fig}
\end{figure}
\lipsum[2]

\begin{figure}[ht]
  \centering 
  \begin{subfigure}{0.45\textwidth}
    \includegraphics{image2}   
    \caption{Case one}
  \end{subfigure}
  \begin{subfigure}{0.45\textwidth}
    \includegraphics{image3} 
    \caption{Case two}
  \end{subfigure}
  \doublecaption[Not very long legend for fig with subfigs.]{Title for fig with subfigs}
\end{figure}
\lipsum[3]

\clearpage
\listoffigures


\end{document}

I can see in the doublecaption definition that the counter is incremented by:

\refstepcounter\@captype

I guess the subcaption package must do something to prevent double-incrementing counters, but I'm not sure how to do this. I can always just explicitly decrement the list counter after the subfigures, but before the figure's doublecaption, but I suspect there's a better way?

share|improve this question
    
Although you're a member since 7 months, this is your first question, so: Welcome to TeX.SX! –  karlkoeller Apr 10 at 8:39

1 Answer 1

up vote 3 down vote accepted

This is a way. Let's define a new command \doublecaption to be used when you want that behavior in the LoF:

\makeatletter
\def\doublecaption{%
   \ifx\@captype\@undefined
     \@latex@error{\noexpand\caption outside float}\@ehd
     \expandafter\@gobble
   \else
     \refstepcounter\@captype
     \expandafter\@firstofone
   \fi
   {\@dblarg{\@doublecaption\@captype}}%
}
\long\def\@doublecaption#1[#2]#3{%
  \par
  \addcontentsline{\csname ext@#1\endcsname}{#1}%
    {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #3\newline#2}}%
  \begingroup
    \@parboxrestore
    \if@minipage
      \@setminipage
    \fi
    \normalsize
    \@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
  \endgroup}
\makeatother

The definition is taken from the normal \caption and modified to fit your needs.

In the tocloft settings, remove

\renewcommand\cftfigaftersnumb{\\}

and add

\newlength\mylength
\settowidth\mylength{\cftfigpresnum}
\addtolength\cftfignumwidth{\mylength}

MWE:

\documentclass{article}

\usepackage[demo]{graphicx}
\usepackage{lipsum}

\usepackage[titles]{tocloft}
\addtocontents{lof}{\cftpagenumbersoff{figure}}
\renewcommand\listfigurename{Figure Legends}
\renewcommand\cftfigpresnum{\bfseries Figure }
\renewcommand\cftfigaftersnum{\bfseries :}
%\renewcommand\cftfigaftersnumb{\\}
\renewcommand{\cftdotsep}{\cftnodots}
\setlength\cftbeforefigskip{12pt}

\newlength\mylength
\settowidth\mylength{\cftfigpresnum}
\addtolength\cftfignumwidth{\mylength}

\makeatletter
\def\doublecaption{%
   \ifx\@captype\@undefined
     \@latex@error{\noexpand\caption outside float}\@ehd
     \expandafter\@gobble
   \else
     \refstepcounter\@captype
     \expandafter\@firstofone
   \fi
   {\@dblarg{\@doublecaption\@captype}}%
}
\long\def\@doublecaption#1[#2]#3{%
  \par
  \addcontentsline{\csname ext@#1\endcsname}{#1}%
    {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #3\newline#2}}%
  \begingroup
    \@parboxrestore
    \if@minipage
      \@setminipage
    \fi
    \normalsize
    \@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
  \endgroup}
\makeatother

\begin{document}

\lipsum[1]
\begin{figure}[ht]
  \centering \includegraphics{image1}
  \doublecaption[Normally a much longer legend for the first figure.]{Title for first fig}
\end{figure}
\lipsum[2]
\begin{figure}[ht]
  \centering \includegraphics{image2}
  \caption{Title for second fig}
\end{figure}

\clearpage
\listoffigures

\end{document} 

Output:

enter image description here


EDIT

Please next time, post examples with all relevant loaded packages...

To let it work with subcaption, we'll define two commands:

  1. \doublecaption, to be used in figures with no subfigures.
  2. \doublesubcaption, to be used in figures with subfigures.

Substitute the above code starting with \makeatletter and ending with \makeatother with this one (require the etoolbox package):

\makeatletter
\let\doublecaption\caption%
\patchcmd{\doublecaption}%
  {\@caption}%
  {\@doublecaption}%
  {}%
  {}%
\let\@doublecaption\@caption%
\patchcmd{\@doublecaption}%
  {\addcontentsline{\csname ext@#1\endcsname}{#1}%
    {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}}%
  {\addcontentsline{\csname ext@#1\endcsname}{#1}%
    {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #3\newline#2}}}%
  {}%
  {}%
\let\doublesubcaption\doublecaption%
\patchcmd{\doublesubcaption}%
  {\refstepcounter\@captype}%
  {\relax}%
  {}%
  {}%
\makeatother

MWE:

\documentclass{article}

\usepackage{amsmath}
\usepackage[demo]{graphicx}
\usepackage{lipsum}
\usepackage{etoolbox}

\usepackage{subcaption}

\usepackage[titles]{tocloft}
\addtocontents{lof}{\cftpagenumbersoff{figure}}
\renewcommand\listfigurename{Figure Legends}
\renewcommand\cftfigpresnum{\bfseries Figure }
\renewcommand\cftfigaftersnum{\bfseries : }
\renewcommand{\cftdotsep}{\cftnodots}
\setlength\cftbeforefigskip{12pt}

\newlength\mylength
\settowidth\mylength{\cftfigpresnum}
\addtolength\cftfignumwidth{\mylength}

\makeatletter
\let\doublecaption\caption%
\patchcmd{\doublecaption}%
  {\@caption}%
  {\@doublecaption}%
  {}%
  {}%
\let\@doublecaption\@caption%
\patchcmd{\@doublecaption}%
  {\addcontentsline{\csname ext@#1\endcsname}{#1}%
    {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}}%
  {\addcontentsline{\csname ext@#1\endcsname}{#1}%
    {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #3\newline#2}}}%
  {}%
  {}%
\let\doublesubcaption\doublecaption%
\patchcmd{\doublesubcaption}%
  {\refstepcounter\@captype}%
  {\relax}%
  {}%
  {}%
\makeatother

\begin{document}

\lipsum[1]
\begin{figure}[ht]
  \centering \includegraphics{image1}
  \doublecaption[Normally a much longer legend for the first figure.]{Title for first fig}
\end{figure}
\lipsum[2]

\begin{figure}[ht]
  \centering
  \begin{subfigure}{0.45\textwidth}
    \includegraphics{image2}
    \caption{Case one}
  \end{subfigure}
  \begin{subfigure}{0.45\textwidth}
    \includegraphics{image3}
    \caption{Case two}
  \end{subfigure}
  \doublesubcaption[Not very long legend for fig with subfigs.]{Title for fig with subfigs}
\end{figure}
\lipsum[3]

\clearpage
\listoffigures


\end{document} 

Output:

enter image description here

share|improve this answer
    
Thanks! I don't quite understand everything you've done yet, but that's great! –  rainbowgoblin Apr 10 at 22:53
    
I've got an additional request: How can I make this cooperate with subcaption (for figure numbering)? See above. –  rainbowgoblin Apr 10 at 23:51
    
@rainbowgoblin See the edit (and remember that you can also upvote the answer, if you want). –  karlkoeller Apr 11 at 5:24
    
Thanks, I didn't realise I had enough points to upvote :) –  rainbowgoblin Apr 11 at 8:22

Your Answer

 
discard

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.