[Tex/LaTex] Vertically align cell table in figure

floatstablesvertical alignment

I have the following figure:

\begin{figure}[ht!]
    \centering
    \begin{tabular}{|c|c|}
        \includegraphics{combo} & \includegraphics{combomenu}
    \end{tabular}
\caption{A combo box with and without showing the menu.}
\label{fig:combos}
\end{figure}

which produces:

enter image description here

The left image is significantly shorther than the right image. How do I vertically align the left image to the top of the cell?

I would already overheat Google with my searches on how to do it, if it would be possible. Nothing I do just seems to have any effect on it:

  • \includegraphics{combo}\hfill does nothing
  • \begin{tabular}{|p{3cm}|c|} does nothing, apart from setting the columnt width
  • \raisebox{4.5\height}{\includegraphics{combo}} indeed moves the image up and down, but I just cannot seem to get the parameter right. Something between 5.5 and 6 it seems. But that's really not what I want, if I decide to change the second image, I would have to go through the painstaking alignment process again.
  • Using minipages aligns the image to the top, but also adds more space to the right from both images and maybe pushes the images too far up, so that the vertical lines begin slightly off:

enter image description here

I specified the images' width in pixels, they are both 82 pixels wide.

Best Answer

The simplest way is to use the adjustbox package:

\documentclass{article}
\usepackage[demo]{graphicx} % just to provide mock figures
\usepackage{adjustbox}

\begin{document}

\begin{tabular}{|c|c|}
\adjustbox{valign=t}{\includegraphics[width=1cm,height=.5cm]{x}} &
\adjustbox{valign=t}{\includegraphics[width=1cm,height=3cm]{x}} \\
\end{tabular}

\end{document}

enter image description here

Without any package,

\begin{tabular}{|c|c|}
\raisebox{\dimexpr-\height+\ht\strutbox}{\includegraphics[width=1cm,height=.5cm]{x}} &
\raisebox{\dimexpr-\height+\ht\strutbox}{\includegraphics[width=1cm,height=3cm]{x}} \\
\end{tabular}

would do the same.

Related Question