Graphics, Figures & Tablesstreamlining caption use for listoffigures

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
rhileighalmgren
Posts: 2
Joined: Wed Feb 10, 2010 1:53 am

streamlining caption use for listoffigures

Post by rhileighalmgren »

When I write captions, I always type the first sentence twice, once in square brackets to use it in the list of figures, and a second time so that it appears underneath the figure with the rest of the caption (as described http://en.wikibooks.org/wiki/LaTeX/Floa ... and_tables). Is there a way to automate the inclusion of the short caption in the long one? I'd prefer not to type it twice, but the bigger problem is forgetting to make changes to both when editing.

I'm envisioning something like:
\begin{figure}[hb]
\includegraphics{someImage}
\caption[The astonishing results were highly significant]
{Unfortunately, the data were fabricated.}
\end{figure}

That would produce a listing in listoffigures:
The astonishing results were highly significant.

and a caption of,
The astonishing results were highly significant. Unfortunately, the data were fabricated.

I could add a kludgy sed command to my typesetting script, but I'd like to go with something as robust as possible.

Thanks!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

streamlining caption use for listoffigures

Post by gmedina »

Hi,

perhaps something along the lines of the command \mycaption
defined below could be useful:

Code: Select all

\documentclass{report}

\newcommand\mycaption[2]{\caption[#1]{#1.\ #2}}

\begin{document}
\listoffigures

\begin{figure}[!ht]
  \centering
  \rule{4cm}{2cm}
  \mycaption{The astonishing results were highly significant}
    {Unfortunately, the data were fabricated.}
  \label{fig:test}
\end{figure}

\end{document}
Please note that both arguments of \mycaption are mandatory so you must use curly braces for both of them.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
rhileighalmgren
Posts: 2
Joined: Wed Feb 10, 2010 1:53 am

Re: streamlining caption use for listoffigures

Post by rhileighalmgren »

Wow. Perfect. Thanks!
Post Reply