[Tex/LaTex] Right-aligned figure while vertically aligning subfigures with beamer

beamersubfloatsvertical alignment

This question is almost a duplicate of this question. The question is asked in a comment, but is never answered.

When vertically aligning two subfigures as suggested in section 5.4 of the subfig-documentation, the second figure becomes right-aligned.

Does anyone know, how to avoid this?

EDIT: The whole thing is top be used in a presentation / Beamer.

An example of my code:

\newsavebox{\tempbox}
\begin{figure}
    \centering
    \sbox{\tempbox}{
        \includegraphics[width=0.35\textwidth]{Figures/superleder.jpg}
    }
    \subfloat[Superleder][Superleder\footnotemark]{\usebox{\tempbox}}
    \subfloat[Neutronstjerne][Neutronstjerne
             \footnote{\url{http://westsalemhigh.com/contract/Tech2/Showcase/Stars/NeutronStar.jpg}}]
            {
    \vbox to \ht\tempbox{
                 \vfil
                 \includegraphics[width=0.35\textwidth]{Figures/neutronstjerne.jpg}
                 \vfil}
             }
\end{figure}
\footnotetext{\url{http://thecustomizewindows.com/wp-content/uploads/2012/06/Superconductor-and-Superconductivity.jpg}}

Best Answer

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 minipages; the height of the bigger image is measured and used as the common height for both minipages (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}

enter image description here

Changing the alignment options for the minipages 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}

enter image description here