# Using the itemize environment inside a caption

The following code does not compile. However, if I remove the itemize environment it does. I googled for this problem, and found suggestions that using the caption package would solve the problem, though I did not find any clear description of why the problem occurred in the first place. See for example

http://www.latex-community.org/forum/viewtopic.php?f=45&t=8774

I'm using Debian squeeze with TeX Live 2009-11. The included version of caption has

\ProvidesPackage{caption}[2009/10/09 v3.1k Customizing captions (AR)]


I also tried downloading and using the caption package from

http://www.ctan.org/tex-archive/macros/latex/contrib/caption/

but this doesn't change anything. I put the sty files in my current directory. I assume that overrides the system files. This one corresponds to

\ProvidesPackage{caption}[2010/01/09 v3.1m Customizing captions (AR)]


Error message and example file follow.

*******************************************
ERROR: Argument of \@caption has an extra }.

--- TeX said ---
<inserted text>
\par
l.13     }

--- HELP ---
From the .log file...

I've run across a }' that doesn't seem to match anything.
For example, \def\a#1{...}' and \a}' would produce
this error. If you simply proceed now, the \par' that
I've just inserted will cause me to report a runaway
argument that might be the root of the problem. But if
your }' was spurious, just type 2' and it will go away.
******************************************************

\documentclass{article}
\usepackage{caption}
\begin{document}

\begin{figure}
\captionsetup{singlelinecheck=off}
\caption
{
foo
\begin{itemize}
\item bar
\end{itemize}
}
\end{figure}
\end{document}

-
The reason for this behaviour is described in the caption package documentation, section 3.1 "Typesetting captions". Look out there for "fragile", "robust", and "into a horizontal box to determine the width of the caption". –  Axel Sommerfeldt Feb 8 '11 at 7:49
I see that entry. The itemize environment causes problems with tex putting the caption text "into a horizontal box to determine the width of the caption", then? Or is the problem something else? –  Faheem Mitha Feb 8 '11 at 8:11
Yes. If in doubt one can try it out by typesetting the stuff outside a \caption, but within a \hbox instead. –  Axel Sommerfeldt Feb 8 '11 at 17:55

From the caption manual:

If you want to typeset something special (like a tabular) as caption, you need to give an optional argument to \caption resp. \captionof for the List of Figures resp. List of Tables, too, even if you don’t use such list.

\documentclass{article}
\usepackage{caption}

\begin{document}

\begin{figure}
\captionsetup{singlelinecheck=off}
\caption[foo bar]{foo
\begin{itemize}
\item bar
\end{itemize}}
\end{figure}

\end{document}

-
Addendum #1: As an alternative for using the optional argument of \caption, one can specify the caption package option list=off if no lists of floating environments (like "List of Figures") are used. –  Axel Sommerfeldt Feb 8 '11 at 7:44
Thanks Leo and Axel. I see this argument is used in the latex community example, but I didn't realize it was necessary. Can anyone explain why this problem occurs in the first place? Axel, not clear what a list of floating environments would look like. –  Faheem Mitha Feb 8 '11 at 7:54
Damn, I see the first entry in the errors subsection has exactly this error, with the solution. –  Faheem Mitha Feb 8 '11 at 8:01