3

I would like to tabulate text within a caption. See below what I obtain with my code:

    \begin{figure}[htbp]
\centering
\includegraphics[width=6in]{topfigure.png}
\includegraphics[width=6in]{bottomfigure.png}
\rule{35em}{0.5pt}
\caption{\begin{tabular}{ll} 
            (top figure)    & Legend of the top figure. \\
            (bottom figure) & The legend of the bottom figure is aligned with the previous one
            \end{tabular}}
\label{fig9} 
\end{figure}

Final wanted result

It actually works, although it gives me the following error message:

! Argument of \caption@ydblarg has an extra }. \par l.183 \end{tabular}}

Any idea how to avoid this error message? Thank you for your help!

1
  • Welcome to TeX.SX! The \begin and \end commands are fragile, in a caption you have to say \protect\begin{tabular}[t]{ll} and \protect\end{tabular} (the [t] is for better vertical alignment).
    – egreg
    Jan 30, 2015 at 23:49

1 Answer 1

5

The problem stems from the fact that the tabular doesn't want to transfer "easily" into the LoF. It would also not make sense to have a tabular construction in the LoF, since the figures won't be there to understand any reference to top/bottom. As such, my suggestion would be to use the optional argument for \caption[<LoF>]{<caption>} (even though you might not use it in the end):

enter image description here

\documentclass{article}
\usepackage{graphicx}
\newcommand{\captionrule}{\rule{.8\linewidth}{0.5pt}}
\begin{document}

\begin{figure}[ht]
  \centering
  \includegraphics[width=2in]{example-image-a}

  \includegraphics[width=2in]{example-image-b}

  \captionrule

  \caption[some ToC entry]{\begin{tabular}{ll@{}} 
              (top figure)    & Legend of the top figure. \\
              (bottom figure) & The legend of the bottom figure.
              \end{tabular}}
\end{figure}

\end{document}

This setup allows you to now also play with the vertical alignment of the tabular. Using \begin{tabular}[t]{..} you'll achieve the following layout:

enter image description here

1
  • Thank you so much @Werner! Thanks to you I learned another functionality of Latex!
    – Chips
    Feb 3, 2015 at 1:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .