3

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}}
3

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

  • I'm doing this in Beamer and when I include the floatrow-package I get the error: "Not in outer par mode. \end{frame}" This happens as soon as I include a figure-float \begin{figure} ... \end{figure}. – Rasmus Søgaard Christensen Sep 12 '13 at 10:04
  • @RasmusSøgaardChristensen you should have mentioned in your question that you were using beamer. – Gonzalo Medina Sep 12 '13 at 15:45
  • I probably should yes, but I didn't realize it made a difference before your answer and more googling. – Rasmus Søgaard Christensen Sep 12 '13 at 16:04
  • @RasmusSøgaardChristensen Yes, sometimes (perhaps always) information about the class is crucial. Please see my updated answer for a possible solution with beamer. – Gonzalo Medina Sep 12 '13 at 17:47
  • Sorry about, but thank you very much for the help. Works like a charm. – Rasmus Søgaard Christensen Sep 12 '13 at 18:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.