4

Consider following code:

\documentclass[a4paper]{article}

\usepackage[table]{xcolor}
\usepackage{graphicx}

\paperheight297mm
\paperwidth210mm

\textheight297mm
\textwidth180mm

\topmargin-25.4mm
\voffset0in
\oddsidemargin-17.5mm
\evensidemargin-17.5mm
\hoffset0in

\marginparsep0in
\marginparwidth0in

\headheight0in
\headsep0in

\begin{document}

\rowcolors{1}{green}{pink}

\begin{table}
\begin{tabular}{p{60mm} p{60mm} p{60mm}}
\includegraphics[height=40mm]{test.png} & 2 & 3 \\[50.8mm]
\includegraphics[height=40mm]{test.png} & 2 & 3 \\[50.8mm]
\includegraphics[height=40mm]{test.png} & 2 & 3 \\[50.8mm]
\includegraphics[height=40mm]{test.png} & 2 & 3 \\[50.8mm]
\includegraphics[height=40mm]{test.png} & 2 & 3 \\[50.8mm]
\end{tabular}
\end{table}

\end{document}

The images are changing the height of the cells. How can I prevent this and how can I vertically center the images?


\documentclass[a4paper]{article}

\usepackage[table]{xcolor}
\usepackage{calc}

\usepackage[top=0pt,bottom=0pt,textwidth=180mm]{geometry}

\begin{document}

\rowcolors{1}{green}{pink}

\begin{table}
\begin{tabular}{*{3}{p{60mm-2\tabcolsep}}}
\raisebox{-.5\height}{\includegraphics[height=40mm,width=50mm]{logo}} & 2 & 3 \\
\end{tabular}
\end{table}

\end{document}

Your code ends in an error:

! Undefined control sequence.<argument> 
\includegraphics[height=40mm,width=50mm]{logo} ...udegraphics[height=40mm,width=50mm]{logo}}
David Carlisle
  • 757,742
Pascal
  • 779

1 Answers1

3

The reference point of an image is at the bottom of its bounding box; with adjustbox you can specify a different vertical alignment. Note also the usage of calc to really get the desired width of the table; I used geometry in order to avoid complicated calculations for the page dimensions.

\documentclass[a4paper]{article}

\usepackage[table]{xcolor}
\usepackage[export]{adjustbox}
\usepackage{calc}

\usepackage[top=0pt,bottom=0pt,textwidth=180mm]{geometry}

\begin{document}

\rowcolors{1}{green}{pink}

\begin{table}
\begin{tabular}{*{3}{p{60mm-2\tabcolsep}}}
\includegraphics[height=40mm,width=50mm,valign=c]{test.png} & 2 & 3 \\
\includegraphics[height=40mm,width=50mm,valign=c]{test.png} & 2 & 3 \\
\includegraphics[height=40mm,width=50mm,valign=c]{test.png} & 2 & 3 \\
\end{tabular}
\end{table}

\end{document}

Note that adjustbox with the export option loads the graphicx package.

Without adjustbox you get the same effect with

\raisebox{-.5\height}{\includegraphics[height=40mm,width=50mm]{test.png}} & 2 & 3 \

(of course loading graphicx is necessary).

David Carlisle
  • 757,742
egreg
  • 1,121,712
  • I don't have the adjustbox package. I work on ubuntu and use Texmaker. How do I get this package? I tried it so far with this: \raisebox{-\height}[10mm]{\includegraphics[height=40mm]{test.png}} \raisebox{-\height}[10mm]{Test} & 2 & 3 \[50.8mm] It works almost, except it changes the height of the cell... – Pascal Aug 14 '12 at 09:29