Line up captions on side by side figures

I want to place two (or more) figures with side by side. The figures are independent, so need separate captions, with no overall caption for the two. I know how to do this with minipages within a figure environment. But the captions don't line up without trail and error \vspace's before the individual captions. Is there a way to line up the captions automatically?

-

You could use the optional argument b to the minipage environments to align the images at their bottom, this way the caption would be side by side. At least you did'nt say if you want the images aligned in another way. Though, a common baseline at their bottom would be good, especially as their captions are aligned.

Here's an example using the caption package:

\documentclass{article}
\usepackage[labelfont=bf]{caption}
\usepackage[demo]{graphicx}
\begin{document}
\begin{figure}[ht]
\begin{minipage}[b]{.4\linewidth}
\centering%
\includegraphics[width=140pt]{test}
\captionof{figure}{First image}
\end{minipage}%
\hfill%
\begin{minipage}[b]{.5\linewidth}
\centering%
\includegraphics[width=180pt,height=50pt]{test}
\captionof{figure}{Second image with caption}
\end{minipage}
\end{figure}
\begin{figure}[ht]
\centering%
\includegraphics{test}
\caption{Another figure}
\end{figure}
\end{document}


Output:

Using the tiny capt-of package would be sufficient. The \captionof command is important. As you can see, the numbering of the subfigures matches the numbering of normal figures.

-
Is there a reason to use a minipage here rather than \parbox? minipage seems unnecessary for almost every problem. –  TH. Nov 27 '10 at 17:51
I have been using the KOMA-script bundle for caption control, and have been having trouble controlling the width of the captions in side-by-side figures. But I find I can change the caption width before side-by-side cases, as here, and then return it to normal: \setcapwidth[c]{.4\textwidth} ... \setcapwidth[c]{.7\textwidth}. It looks good. –  brannerchinese Aug 29 '12 at 0:58

Would subfigure (omitting the caption argument and only using subcaptions) solve your problem? (See this example)

EDIT: Subfigure has apparently been replaced by subfig.

-

Use the floatrow package, particularly its floatrow environment and \ffigbox command.

\documentclass{article}

\usepackage[format=hang]{caption}

\usepackage{floatrow}

\begin{document}

\begin{figure}
\begin{floatrow}
\ffigbox{%
\rule{3cm}{3cm}%
}{%
\caption{A figure}%
}
\ffigbox{%
\rule{2cm}{2cm}%
}{%
\caption{Another figure with a long caption}%
}
\end{floatrow}
\end{figure}

\end{document}

-