5

I have table with text in the first column and image in second. I want both columns to be top aligned. I use following code:

\begin{tabular}{p{3cm}l}
Internal state after adding 2 elements & \includegraphics[scale=0.4]{pics/queue_after_add.png} \\
Internal state non-concurrent execution & \includegraphics[scale=0.4]{pics/queue_sequential.png} \\
Internal state concurrent execution & \includegraphics[scale=0.4]{pics/queue_concurrent.png}\\
\end{tabular}

The result looks like this: enter image description here

I also tried to insert \vspace{0pt} as some thread suggests, but result was the same.

damluar
  • 679

2 Answers2

5

\vspace{0pt} would work if the graphics were in a column of type p{..}. In l-columns you will have to move the graphics below the baseline with \raisebox{-\height}{....}.

Ulrike Fischer
  • 327,261
1

The solution is to use the package 'array'. And then use m instead of the p boxes you have in argument of tabular environment.

\usepackage{array}        
\begin{tabular}{m{3cm}m{5cm}}
    Internal state after adding 2 elements & \includegraphics[scale=0.4]{pics/queue_after_add.png} \\
    Internal state non-concurrent execution & \includegraphics[scale=0.4]{pics/queue_sequential.png} \\
    Internal state concurrent execution & \includegraphics[scale=0.4]{pics/queue_concurrent.png}\\
    \end{tabular}

Now I have no idea how this works. I found this solution online, after a painful 4 hours of trying to fix a similar issue. And no forum seems to explain why tabular environment by itself cannot fix this. So counter-intuitive!

ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
user38161
  • 11
  • 1