Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
AFAIK there are several ways you could tackle that, see for example: tex.stackexchange.com/q/51564 or tex.stackexchange.com/q/67052 and tex.stackexchange.com/q/6355 –  Count Zero Dec 2 '12 at 14:41
    
@CountZero pls see edit –  Jakub Zaverka Dec 2 '12 at 15:00
    
Without any packages, \raisebox{-\height}{\includegraphics[...]{...} should do. –  egreg Dec 2 '12 at 15:03
    
@egreg that commang pushes the image even more downwards. –  Jakub Zaverka Dec 2 '12 at 15:10
add comment

3 Answers

up vote 5 down vote accepted

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.

share|improve this answer
    
This works nicely. Thank you. –  Jakub Zaverka Dec 2 '12 at 15:22
    
@JakubZaverka: If you load adjustbox (v0.8 or later) with the export option you can use the valign key directly with \includegraphics, after the size keys. –  Martin Scharrer Feb 5 '13 at 22:51
add comment

Another minipage solution with a few more optional arguments.

\documentclass{article}
\usepackage{graphicx}
\usepackage{mwe} %< -- For dummy images

\begin{document}%
\begin{figure}
    \centering
    \begin{tabular}{|c|c|}
        \begin{minipage}[b][6cm][t]{2cm} %[minipage place][height][content align]{width}
        \includegraphics[width=2cm,height=1cm]{example-image-a}%
        \end{minipage}
            & \includegraphics[width=2cm,height=6cm]{example-image-b}
    \end{tabular}
\caption{A combo box with and without showing the menu.}
\label{fig:combos}
\end{figure}
\end{document}

enter image description here

share|improve this answer
add comment

I would put both \includegraphics commands inside minipages as follows:

\begin{minipage}[t]{<width-of-image>}
    \vspace{-\baselineskip}\par
    \includegraphics{combo}
\end{minipage}
&
\begin{minipage}[t]{<width-of-image>}
    \vspace{-\baselineskip}\par
    \includegraphics{combomenu}
\end{minipage}

Though I might be wrong.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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