Vertically align subfloats at the top while having subcaptions vertically aligned below the subfloats
As suggested by Mico in his answer it can be done with the floatrow
package. To make subcaptions it depends on subcaption
which depends on caption
.
\documentclass{article}
\usepackage{tikz}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{floatrow}
\usepackage{calc}% To calculate width for \FBwidth
\floatsetup{
heightadjust=object,
valign=t
}
\begin{document}
\begin{figure}
\ffigbox
{%
\begin{subfloatrow}
\ffigbox[\FBwidth+0.5cm]% Width of subfloat
{%
\begin{tikzpicture}
\draw circle (1.25cm) {};
\end{tikzpicture}%
}
{%
\subcaption{Small circle}%
}
\ffigbox[\FBwidth+0.5cm]% Width of subfloat
{%
\begin{tikzpicture}
\draw circle (2cm) {};
\end{tikzpicture}%
}
{%
\subcaption{Big circle}%
}
\end{subfloatrow}
}
{%
\caption{Circles}%
}
\end{figure}
\end{document}
Not an automatic procedure, but not so difficult to use:
\documentclass{article}
\usepackage{tikz}
\usepackage{subfig}
\newcount\bsubfloatcount
\newtoks\bsubfloattoks
\newdimen\bsubfloatht
\makeatletter
\newcommand{\bsubfloat}[2][]{%
\sbox\z@{#2}%
\ifdim\bsubfloatht<\ht\z@
\bsubfloatht=\ht\z@
\fi
\advance\bsubfloatcount\@ne
\@namedef{bsubfloat\romannumeral\bsubfloatcount}{%
\subfloat[#1]{\vbox to\bsubfloatht{\hbox{#2}\vfill}}}%
}
\newcommand{\resetbsubfloat}{\bsubfloatcount\z@\bsubfloatht=\z@}
\makeatother
\begin{document}
\begin{figure}
\centering
\bsubfloat[Small circle]{%
\begin{tikzpicture}
\draw circle (1.25cm) {};
\end{tikzpicture}%
}
\bsubfloat[Big circle]{%
\begin{tikzpicture}
\draw circle (2cm) {};
\end{tikzpicture}%
}
\bsubfloati\qquad\bsubfloatii
\caption{Circles}
\end{figure}
\end{document}
The \bsubfloat
commands are just for doing the calculation, then you can use \bsubfloati
, \bsubfloatii
, \bsubfloatiii
, \bsubfloativ
and so on (they are reset on each figure
environment) to set up the row of subfloats.
If you have multiple rows, you should use \resetbsubfloat
between them and use again \bsubfloati
and so on for the placement.
More automatic procedure
Here is one, it has some weaknesses, but it should work.
\documentclass{article}
\usepackage{tikz}
\usepackage{subfig}
\newtoks\bsubfloattoks
\newdimen\bsubfloatht
\makeatletter
\newenvironment{bsubfloatrows}[1][\quad]
{\def\bsubfloatspace{#1}\resetbsubfloatrows
\def\\{\printbsubfloatrow\resetbsubfloatrows\par
\@ifnextchar[{\bsubfloatvspace}{}}%
\def\bsubfloatvspace[##1]{\vspace{##1}}%
}
{\printbsubfloatrow}
\newcommand{\bsubfloat}[2][]{%
\sbox\z@{#2}%
\ifdim\bsubfloatht<\ht\z@
\bsubfloatht=\ht\z@
\fi
\bsubfloattoks=\expandafter{\the\bsubfloattoks
\bsubfloatspace\subfloat[#1]{\vbox to\bsubfloatht{\hbox{#2}\vfill}}}%
}
\newcommand\resetbsubfloatrows{\bsubfloatht\z@\bsubfloattoks={\@gobble}}
\newcommand{\printbsubfloatrow}{\the\bsubfloattoks}
\makeatother
\begin{document}
\begin{figure}
\centering
\begin{bsubfloatrows}[\hfill]
\bsubfloat[Small circle]{%
\begin{tikzpicture}
\draw circle (1.25cm) {};
\end{tikzpicture}%
}
\bsubfloat[Big circle]{%
\begin{tikzpicture}
\draw circle (2cm) {};
\end{tikzpicture}%
}
\\[36pt]
\bsubfloat[Small circle]{%
\begin{tikzpicture}
\draw circle (1cm) {};
\end{tikzpicture}%
}
\bsubfloat[Big circle]{%
\begin{tikzpicture}
\draw circle (1.2cm) {};
\end{tikzpicture}%
}
\end{bsubfloatrows}
\caption{Circles}
\end{figure}
\end{document}
As you see, subfloats are enclosed in an environment, where each row is processed separately as regards the height. The horizontal spacing between two subfloats is given as optional argument to the environment (that's one weakness).
A quick introductory remark: According to the latest edition of the l2tabu
document, both the subfigure
and subfig
packages should no longer be used; instead, one should use the subcaption
package (from the same author of the caption
package).
The problem you describe might best be solved using the floatrow
package, as it provides all kinds of ways of aligning both the contents of side-by-side (sub)figures and their respective captions. Unfortunately, I find the writing style of the package's manual rather hard to penetrate, so I wasn't able to come up with a working MWE. Hopefully you'll have better luck. :-)