The problem with that solution using \vbox
without extra precautions is that the box produced by \vbox
will have a width equal to \textwidth
; the second subfigure is "pushed to the right" by the first subfigure and this results in an overfull \hbox
(you should see the warning message in the output console).
Now that the question has been edited to mention this is for the beamer
class. here's an option using \subcaptionbox
and some minipage
s; the height of the bigger image is measured and used as the common height for both minipage
s (if no captions are required, the same principle can be applied, without \subcaptionbox
):
\documentclass{beamer}
\usepackage{subcaption}
\newsavebox\myfigbox
\savebox\myfigbox{\includegraphics[height=6cm,width=3cm]{example-image-a}}
\newlength\FigHt
\settoheight\FigHt{\usebox\myfigbox}
\begin{document}
\begin{frame}
\begin{figure}
\subcaptionbox{left subfigure}{%
\begin{minipage}[c][\FigHt][c]{4cm}
\centering
\usebox\myfigbox
\end{minipage}%
}
\subcaptionbox{right subfigure}{%
\begin{minipage}[c][\FigHt][c]{4cm}
\centering
\includegraphics[height=3cm,width=3cm]{example-image-a}
\end{minipage}%
}
\end{figure}
\end{frame}
\end{document}
Changing the alignment options for the minipage
s one can easily achieve top, bottom alignment.
In cases like this, with the standard classes, the powerful floatrow
package makes the job trivial, using its heightadjust
and valign
keys:
\documentclass{article}
\usepackage{subcaption}
\usepackage{floatrow}
\usepackage{graphicx}
\begin{document}
\thisfloatsetup{heightadjust=all,valign=t}
\begin{figure}
\begin{subfloatrow}
\ffigbox[\dimexpr\FBwidth+4cm\relax]
{\includegraphics[width=3cm,height=5cm]{example-image-b}}
{\caption{Left subfigure}\label{sfig:testa}}%
\ffigbox[\FBwidth]
{\caption{Right subfigure}\label{sfig:testb}}
{\includegraphics[width=3cm,height=2cm]{example-image-a}}
\end{subfloatrow}
\end{figure}
\thisfloatsetup{heightadjust=all,valign=c}
\begin{figure}
\begin{subfloatrow}
\ffigbox[\dimexpr\FBwidth+4cm\relax]
{\includegraphics[width=3cm,height=5cm]{example-image-b}}
{\caption{Left subfigure}\label{sfig:testc}}%
\ffigbox[\FBwidth]
{\caption{Right subfigure}\label{sfig:testd}}
{\includegraphics[width=3cm,height=2cm]{example-image-a}}
\end{subfloatrow}
\end{figure}
\thisfloatsetup{heightadjust=all,valign=b}
\begin{figure}
\begin{subfloatrow}
\ffigbox[\dimexpr\FBwidth+4cm\relax]
{\includegraphics[width=3cm,height=5cm]{example-image-b}}
{\caption{Left subfigure}\label{sfig:teste}}%
\ffigbox[\FBwidth]
{\caption{Right subfigure}\label{sfig:testf}}
{\includegraphics[width=3cm,height=2cm]{example-image-a}}
\end{subfloatrow}
\end{figure}
\end{document}
I would use the subcaption
package and \phantomsubcaption
(or \phantomcaption
if you decide to use e.g., subfigure
environment). Note that you need version 1.1 of the subcaption package.
Below is your adapted MME:
\documentclass{memoir}
\usepackage{tikz,siunitx,mwe}
\usepackage{subcaption}
\newsubfloat{figure}
\newcommand{\scalebarimg}[6]{
\begin{tikzpicture}
\draw node[name=micrograph] {\includegraphics[width=#2\textwidth]{#1}}; %I fetch the image
\draw[ultra thick,#6] (micrograph.south west)++(0.03*0#2\textwidth,0.035*0#2\textwidth)--++(#2*#3\textwidth,0)node[above,midway]
{#4 \si{\micro\meter}}; %I draw the scalebar
\draw (micrograph.north west) node[anchor=north west,yshift=-1,#6]{\textbf{\small{#5}}}; %I draw the image label
\end{tikzpicture}
}
\begin{document}
\begin{figure}
{\phantomsubcaption\label{fig:one}
\scalebarimg{example-image}{.45}{0.33933}{50}{\subref{fig:one}}{black}}
{\phantomsubcaption\label{fig:two}
\scalebarimg{example-image}{.45}{0.33933}{50}{\subref{fig:two}}{white}}
\caption{Figures (a) and (b) should not be doubly labeled.}
\end{figure}
See Figure~\ref{fig:one} and \subcaptionref{fig:two}.
\end{document}
I surrounded each subfigure with just {}
(needed to separate figure from subfigure) but you can put them for example in minipage
, subfigure
etc. If you want to customise label, see subcaption
documentation.
Best Answer
If your aim is to equalize the spaces, then
\null\hfill
is not the right way. Note that\null
does not start horizontal mode (that is, a paragraph), so all it does is to create some vertical space.Note also that
subfigure
has been obsolete and deprecated for 15 years.