38

I want to create a table with multiple rows of the following form: a cell that contains text and then multiple cells that contain images. The text should be vertically centered and the contents of every column should also be centered horizontally. I am aware of the m{} column type but somehow this seems to fail if an image is contained in the row and determines the row height. Any ideas?

Minimal example:

\documentclass{article}
\usepackage{graphicx}
\usepackage{array}
\begin{document}
\begin{figure}
\begin{tabular}{m{3cm}c}
(a) & \includegraphics{some_picture.pdf}\\
\end{tabular}
\end{figure} 
\end{document}
  • Welcome to tex.sx! A tip: you can use backticks ` to mark your inline code as I did in my edit. Also, it isn't really a custom here to sign with a "thanks". Finally a suggestion: Maybe change your username to something more telling than "user5506"? – doncherry May 26 '11 at 9:15
59

The baseline of an image is at the bottom. You could use \raisebox to shift it up. Use half of \height, which stands for the height of the box to be raised.

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

For example:

\documentclass{article}
\usepackage{mwe}
\begin{document}
\begin{tabular}{lll}
\raisebox{-.5\height}{\includegraphics[scale=0.25]{example-image}} & text & text\\
\end{tabular}
\end{document}

yields:

enter image description here

36

The new graphbox package introduces a new (vertical) align key which can be used in \includegraphics options. Using it there's no need for \raisebox, \parbox or taking care of distinguishing between c or m columns in tabulars.

\documentclass{article}
\usepackage{mwe}
\usepackage{graphbox} %loads graphicx package
\begin{document}
\begin{tabular}{ccc}
text & \includegraphics[scale=0.25]{example-image} & text\\
text & \includegraphics[align=c,scale=0.25]{example-image} & text\\
text & \includegraphics[align=t,scale=0.25]{example-image} & text\\
\end{tabular}
\end{document}

enter image description here

As egreg reminded me, adjustbox package provides a similar funcionality. Loading it with export option, a new key valign={t|m|b|T|M|B} can be used as \includegraphics option.

\documentclass{article}
\usepackage{mwe}
\usepackage[export]{adjustbox}
\begin{document}
\begin{tabular}{ccc}
text & \includegraphics[valign=m,scale=0.25]{example-image} & text \\
\end{tabular}
\end{document}
  • 2
    The same functionality (with the key valign) is available with \usepackage[export]{adjustbox}. – egreg Sep 5 '14 at 10:41
  • @egreg Thank you for reminding me about adjustbox. – Ignasi Sep 5 '14 at 12:03
  • And thank you for advertising a new package! – egreg Sep 5 '14 at 12:08
5

use the m column type for the image, eg:

\begin{tabular}{c m{4cm}}
0

A variant of @Herbert's answer that gives vertically and horizontally centered column alignment is the following. (This is my preferred method when not using \includegraphics.)

\begin{tabular}{
  >{\centering\arraybackslash}m{.4\linewidth} % col width
  >{\centering\arraybackslash}m{.4\linewidth} % col width
}
% an image, tikz picture, etc.
&
% another image, tikz picture, etc.
\end{tabular}
0

Based on the answer of Stefan Kottwitz I wrote this little snippet to make it a little easier to implement:

\newcommand{\tabfigure}[2]{\raisebox{-.5\height}{\includegraphics[#1]{#2}}}

To be used as:

\documentclass{article}
\usepackage{mwe}
\newcommand{\tabfigure}[2]{\raisebox{-.5\height}{\includegraphics[#1]{#2}}}
\begin{document}

    \begin{tabular}{cc}
    a bit of text &    \tabfigure{width=0.20\textwidth}{example-image}
    \end{tabular}

\end{document}

enter image description here

PS: wanted to write is as comment because it's basically the same answer, but I don't have enough rep yet...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.