# Vertical centered image in cell

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

\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}}

-
–  Joseph Wright Aug 14 '12 at 8:58
Could you add a picture of the output? –  doncherry Aug 14 '12 at 16:52
I´ll try this one tex.stackexchange.com/questions/4693/… –  HotPizzaBox Aug 16 '12 at 6:04

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{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).

-
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... –  HotPizzaBox Aug 14 '12 at 9:29