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'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?

share|improve this question

migrated from stackoverflow.com Jul 19 '11 at 17:14

This question came from our site for professional and enthusiast programmers.

    
why not just call the two images with the same height instead of width? –  Mica Sep 24 '09 at 0:15
    
"The first image is shorter than the second" –  shoosh Sep 24 '09 at 7:59
    
it doesn't matter since you're scaling them anyway. –  Mica Sep 24 '09 at 16:04
    
1  
Does the [t] flag works in your case? \begin{tabular}[t]{c|c} ... \end{tabular} –  user21868 Nov 7 '12 at 13:31

3 Answers 3

up vote 18 down vote accepted
\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}
share|improve this answer
    
It works! Thanks! –  shoosh Sep 24 '09 at 8:42
    
Could you possibly provide any insight on what's going on here though? –  shoosh Sep 24 '09 at 8:45
2  
\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 Sep 24 '09 at 10:37
1  
This does not seem to work when the object in the tabular is a tikzpicture. Ideas? –  JohnD May 8 '12 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 Jun 19 '12 at 23:29

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}}
share|improve this answer
    
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 Jun 22 '12 at 17:28

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!

share|improve this answer

Your Answer

 
discard

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