28

When putting a graphics inside a table, the text at the right is too much at the bottom

Minimum example :

\documentclass{article}[12pt]
\usepackage{graphicx} % This is already loaded by the atlasnote class
                       % Just use it to include your plots!

\begin{document}

abc
\begin{table}[h!]
\begin{center}
\begin{tabular}{|c|l|c|}
\hline
ABCD, put me at the top     &\includegraphics[height=2.5cm]{invariant_mass_eX_Asymmetric}   &line1, i wish to be much more at the top\\
&                               &line2, idem\\
&                               &line3, idem\\
&                               &line4, idem\\
\hline
\end{tabular}
\end{center}
\end{table}

def

\end{document}

Current output:

enter image description here

I read the link Insert image and list inside a table but this didn't resolve my problem.

Moriambar
  • 11,466
Joe
  • 281

3 Answers3

30

The default alignment point of an image is its bottom edge you can use

\raisebox{-.5\height}{\includegraphics}{...}}

To put the alignment in the middle, or more generally use any length instead of -.5\height The adjustbox package offers some nicer syntax to such things.

David Carlisle
  • 757,742
  • ...and the syntax is valign=c. – Werner May 07 '13 at 14:06
  • thanks. it helps to put above the first line, but not the others. – Joe May 07 '13 at 14:08
  • @Joe Your line2 is in the following row of the table so of course it comes below. perhaps you want to make the last column p{3cm} instead of c and then put line 1... line2... all in one multi-line entry – David Carlisle May 07 '13 at 14:12
  • How to get rid of the annoying vertical white space on top of the image? – yegor256 Aug 15 '21 at 04:07
  • @yegor256 don't ask new questions as comments on years old answers to other questions. I have no idea which space you find annoying, please post a new question with an example document showing the bad space. – David Carlisle Aug 15 '21 at 07:17
3

Here's my attempt...

  • I changed the middle column of the table from an l column to a p{5.2cm} column. That puts the cells in that column in a paragraph of width 5.2cm (change that according to your image size).

  • I put \vspace{0cm} before the image. Don't ask me why, but it seems to work ok!

Result:

enter image description here

Code (the demo option makes the black image placeholder):

\documentclass[demo]{article}[12pt]
\usepackage{graphicx} % This is already loaded by the atlasnote class
                       % Just use it to include your plots!

\begin{document}

abc
\begin{table}[h!]
\begin{center}
\begin{tabular}{|c|p{5.2cm}|c|}
\hline
ABCD, put me at the top     &\vspace{0cm}\includegraphics[height=2.5cm]{invariant_mass_eX_Asymmetric}   &line1, i wish to be much more at the top\\
&                               &line2, idem\\
&                               &line3, idem\\
&                               &line4, idem\\
\hline
\end{tabular}
\end{center}
\end{table}

def

\end{document}

Update

In response to the OP's request for line2, line3 and line4 to move upwards as well:

  • Following David Carlisle's suggestion, you can use \raisebox to move the image downwards.

  • You can then smash the image, which makes LaTeX think the image has no height. This trick means that the image could overlap the bottom of the table, but that won't be a problem if you have enough text in the other two columns.

Result:

enter image description here

Code:

\documentclass[demo]{article}[12pt]
\usepackage{graphicx} % This is already loaded by the atlasnote class
                       % Just use it to include your plots!

\begin{document}

abc
\begin{table}[h!]
\begin{center}
\begin{tabular}{|c|l|c|}
\hline
ABCD, put me at the top     &\smash{\raisebox{-\height}{\includegraphics[height=2.5cm]{invariant_mass_eX_Asymmetric}}}   &line1, i wish to be much more at the top\\
&                               &line2, idem\\
&                               &line3, idem\\
&                               &line4, idem\\
\hline
\end{tabular}
\end{center}
\end{table}

def

\end{document}
David Carlisle
  • 757,742
  • thank you. my last problem is that i wish the line2, line3, line4 to be at the right of the figure, not at the "bottom". Do you have an idea ? – Joe May 07 '13 at 14:05
  • thank you very much. This is exactly what i was looking for. Thanks a lot, you made me save a huge amount of time. – Joe May 07 '13 at 14:32
  • You're welcome. Please consider clicking on the tick mark next to my answer to 'accept' it, so that this question can be marked as resolved. :) – John Wickerson May 07 '13 at 16:26
1

Here is an approach using multirow.sty that works pretty well out of the box:

\documentclass[demo]{article}
\usepackage{graphicx} 
\usepackage{multirow}

\begin{document}

abc
\begin{table}[h!]
\begin{center}
\begin{tabular}{|l|c|c|}
\hline
ABCD, put me at the top&
    \multirow{4}{*}{\includegraphics[height=2.5cm]{invariant_mass_eX_Asymmetric.pdf}}&
    line1, i wish to be much more at the top\\
&                               &line2, idem\\
&                               &line3, idem\\
&                               &line4, idem\\
\hline
\end{tabular}
\end{center}
\end{table}

def

\end{document}

Output:

enter image description here

Moriambar
  • 11,466
sgmoye
  • 8,586