views:

6704

answers:

4

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  A: 
Alexey Malistov
It works! Thanks!
shoosh
Could you possibly provide any insight on what's going on here though?
shoosh
\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.
Alexey Malistov
A: 

This works fine except of the fact that it creates an empty line on top of the image. As long as there are only images in one row that's not an issue; however, mixing text columns with picture columns will lead to an incorrect vertical alignment, i.e. the empty line is annoying.

Does anyone know how to avoid that?

WLanger
A: 

I was searching the same (alignment of images with text in tables) and thanks to Alexey I got the answer in your post...

Naeem
+1  A: 

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!

Dave MH