32

I'm trying to create a simple tabular with two cells of text and two images below them like so:

\begin{tabular}[h]{ c | c}
    \emph{Normal} & \emph{Cone} \\
    \includegraphics[width=0.39\textwidth]{images/pipe1} &
    \includegraphics[width=0.61\textwidth]{images/pipe2}        
\end{tabular}

The first image is shorter than the second and I want it to be aligned at the top of the cell but for some reason it gets aligned to the bottom of the cell instead.

I've tried using the array package and do this:

\begin{tabular}[h]{ p{0.39\textwidth} | p{0.61\textwidth} }
    \emph{Normal} & \emph{Cone} \\
    \includegraphics[width=0.39\textwidth]{images/pipe1} &
    \includegraphics[width=0.61\textwidth]{images/pipe2}        
\end{tabular}

But this doesn't change anything. The first image is still aligned to the bottom.
Why is that?
Could there be something else going on which forces the alignment to stick to the bottom?

5
  • why not just call the two images with the same height instead of width?
    – Mica
    Commented Sep 24, 2009 at 0:15
  • "The first image is shorter than the second"
    – shoosh
    Commented Sep 24, 2009 at 7:59
  • it doesn't matter since you're scaling them anyway.
    – Mica
    Commented Sep 24, 2009 at 16:04
  • See how to vertically align a cell in a table?. Commented Jul 19, 2011 at 17:17
  • 1
    Does the [t] flag works in your case? \begin{tabular}[t]{c|c} ... \end{tabular}
    – user21868
    Commented Nov 7, 2012 at 13:31

3 Answers 3

28
\def\imagetop#1{\vtop{\null\hbox{#1}}}

\begin{tabular}{c|c}
  \emph{Normal} & \emph{Cone} \\
  \imagetop{\includegraphics[width=0.39\textwidth]{images/pipe1}}&
  \imagetop{\includegraphics[width=0.61\textwidth]{images/pipe1}}
\end{tabular}
5
  • 4
    Could you possibly provide any insight on what's going on here though?
    – shoosh
    Commented Sep 24, 2009 at 8:45
  • 3
    \def\imagetop#1{...} is the definition you need. \vtop creates a verical box. This box contains two elements: an empty horizontal box (\null) and horizontal box with your picture. Also this box is aligned to the first empty horizontal box. Commented Sep 24, 2009 at 10:37
  • 3
    This does not seem to work when the object in the tabular is a tikzpicture. Ideas?
    – JohnD
    Commented May 8, 2012 at 4:06
  • It works even inside an \array environment, inside the $$ environment... I mean: \begin{figure}[ht!];$\begin{array}{rl};\textnormal{(a)} & \imagetop{\includegraphics{...}}\\;\textnormal{(b)} & \imagetop{\includegraphics{...}};\end{array}$;\caption{\label{lbl}caption};\end{figure} (the ";" stands for line break in the text!)
    – Girardi
    Commented Jun 19, 2012 at 23:29
  • @AlexeyMalistov: Could you please also explain how to do this when you want to vertical align text to top? Commented May 9, 2013 at 7:07
7

The topic has been discussed (and solved) in German here: http://www.matheplanet.com/matheplanet/nuke/html/viewtopic.php?topic=133671

In your case, try:

\begin{tabular}[h]{ c | c}
    \emph{Normal} & \emph{Cone} \\
    \raisebox{-\height+\baselineskip}{\includegraphics[width=0.39\textwidth]{images/pipe1}} &
    \raisebox{-\height+\baselineskip}{\includegraphics[width=0.61\textwidth]{images/pipe2}}
\end{tabular}

This should also solve the problem of the empty line above.

If you would like to stick with the imagetop command, try:

\def\imagetop#1{\raisebox{-\height+\baselineskip}{#1}}
2
  • 1
    Are you sure the link is right? All I can see is some guys discussing the fairly basic topic of what a \baselineskip is at a length I wouldn't have thought possible. Nothing about vertical alignment AFAICS.
    – Christian
    Commented Jun 22, 2012 at 17:28
  • Would be useful to mention that this needs calc. There's a tutorial here that explains it in detail: peteryu.ca/tutorials/publishing/… Commented Jan 22, 2021 at 11:50
6

Regarding WLanger's question about Alexey's solution: to adjust for the empty line on top of the image, put the text into a \parbox, and use \raisebox (with a negative value) to adjust it's vertical position.

\raisebox{value}{your text here} % will lower text if it has a negative value.

\parbox{width}{your text here} % will allow for text wrapping

You will have to nest them, like this:

\raisebox{value}{\parbox{width}{your text goes here}}

So the result will be this:

\def\imagetop#1{\vtop{\null\hbox{#1}}}

\begin{tabular}[h]{c|c}        
  \emph{Normal} & \emph{Cone} \\        
  \imagetop{\includegraphics[width=0.39\textwidth]{images/pipe1}} & \raisebox{-1cm}{\parbox{8cm}{Replace this with your text, and adjust the raisebox and parbox values to your liking. I don't know the measurements of the images you're using or I'd do it for you.}
  \imagetop{\includegraphics[width=0.61\textwidth]{images/pipe1}}
\end{tabular}

It isn't elegant, but it works!

You must log in to answer this question.