[OS X TeX] "Runaway argument?" error in figure caption

Alan Munn amunn at gmx.com
Tue Jul 17 11:46:37 EDT 2012


From: Manfred Braun

 On 17.07.2012, at 16:38, John B. Thoo wrote: > Hi, everyone. I apologize that this is not a Mac-specific question, but rather a general LaTeX question; however, I don't know whom else to ask. > > This code > > \begin{figure} > \begin{tikzpicture} > \pgftransformscale{0.75} > %% axes > \draw[help lines,lightgray] (-1,-1) grid (5,5); > \draw[thin] (-1,0) -- (5,0) node[anchor=north]{$x$}; > \draw[thin] (0,-1) -- (0,5) node[anchor=west]{$y$}; > %% u and (u1,u2) > \draw[thick,-latex] (0,0) -- (3,4); > \draw (1.6,2) node[anchor=west]{$\vec{u} = \left[\begin{array}{c} 3 \\ 4 \end{array}\right]$}; > \fill (3,4) circle (0.08) node[anchor=west]{$(3,4)$}; > \end{tikzpicture} > \caption{It is useful to picture vectors as arrows, although this may not be a literal representation of vectors. Here we identify the vector $\vec{u} = \left[\begin{smallmatrix} 3 \\ 4 \end{smallmatrix}\right]$ in $\R{2}$ represented as an arrow with the point $(3,4)$ in the $xy$ plane.} > \label{fig.syslineqns:vectorasarrow} > \end{figure} > > produces this error > > [5] > ! Argument of \@caption has an extra }. > <inserted text> > \par > l.177 ...ith the point $(3,4)$ in the $xy$ plane.} Within a caption the use of commands and environments is restricted. Commands must be "protected". A possible solution is as follows: Define, for instance, \newcommand\mymatrix{ \left[ \begin{smallmatrix} 3 \\ 4 \end{smallmatrix} \right] } in the preamble. Then replace your caption by \caption{It is useful to picture vectors as arrows, although this may not be a literal representation of vectors. Here we identify the vector $\vec{u} = \protect\mymatrix$ in $\R{2}$ represented as an arrow with the point $(3,4)$ in the $xy$ plane.} This should work. Important is to include the \protect command. It prevents the immediate expansion of the subsequent \mymatrix command, the expansion is postponed until the caption is typeset. Manfred
 Alternatively, you can load the caption package and provide an alternative title for the caption to be used in the list of figures:

 \usepackage{caption}

 \begin{figure}
 ...
 \captionsetup{singlelinecheck=off}
 \caption[stuff for list of figures]{stuff for the actual caption}
 \end{figure}

 Alan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://email.esm.psu.edu/pipermail/macosx-tex/attachments/20120717/cddeff4a/attachment.html>


More information about the MacOSX-TeX mailing list