# vertical aligning images in table with \adjustbox only works when not every image is in an \adjustbox

I'm trying to center all images vertically and horizontally within a table cell.

Therefore I'm using the adjustbox packet. This is the code I use for my table:

 \begin{table}[b]
\begin{center}
\begin{tabular}{ |c|c|c|c|c| }
\hline
\includegraphics[width=2cm,height=1cm,keepaspectratio]{./images/buttons/Windows-Buttons.png}
}
&
\includegraphics[width=2cm,height=1cm,keepaspectratio]{./images/buttons/MacOSX-Buttons.png}
}
&
[...]
&
\includegraphics[width=2cm,height=1cm,keepaspectratio]{./images/buttons/Android-Buttons.png}
}

\\[.8cm]

\hline
Windows 7 & Mac OS X & Gnome & iOS & Android \\
\hline
\end{tabular}
\end{center}

\vspace{-.5cm}
\caption{Buttons verschiedener Betriebssysteme}
\end{table}


If I attach adjustbox to every \includegraphics I don't get the desired output:

If I remove only one \adjustbox (no matter which one), with following code:

%\adjustbox{valign=m}{
\includegraphics[width=2cm,height=1cm,keepaspectratio]{./images/buttons/MacOSX-Buttons.png}
%}


I get the desired result (well, some kind of ...):

I don't have to use \adjustbox. I just want the images to be vertically and horizontally centered.

-
Welcome to TeX.SX. Pleas always post complete, compilable but minimal examples, i.e. add a small preamble etc. Some general notes: Please add a % on lines ending on { to avoid getting a space here from the line break, i.e. write \adjustbox{valign=m}{%. Note that with the export option of adjustbox you can use valign=m directly as \includegraphics option. There is also a \adjustimage macro. The center environment should not be used inside table. See Should I use center or centering for figures and tables? –  Martin Scharrer Jan 4 '13 at 20:55

This is not an issue with adjustbox. The first image is exactly what your code requests: All images vertically aligned plus 0.8cm whitespace at the bottom. Apparently you want also some whitespace on top, which is however not the job of valign. You may use the margin option of adjustbox here.

\documentclass{article}

\usepackage{mwe}% for this example only

\begin{document}

\lipsum % example text

\begin{table}[b]
\centering
\begin{tabular}{ |c|c|c|c|c| }
\hline
\includegraphics[width=2cm,height=1cm,keepaspectratio,valign=m,margin=0cm .8cm]{example-image}
&
\includegraphics[width=2cm,height=1cm,keepaspectratio,valign=m,margin=0cm .8cm]{example-image-a}
&
\includegraphics[width=2cm,height=1cm,keepaspectratio,valign=m,margin=0cm .8cm]{example-image-b}
&
\includegraphics[width=2cm,height=1cm,keepaspectratio,valign=m,margin=0cm .8cm]{example-image-c}
&
\includegraphics[width=2cm,height=1cm,keepaspectratio,valign=m,margin=0cm .8cm]{example-image-1x1}
\\
\hline
Windows 7 & Mac OS X & Gnome & iOS & Android \\
\hline
\end{tabular}
\caption{Buttons verschiedener Betriebssysteme}
\end{table}

\lipsum % example text

\end{document}


However 0.8cm seems to be a little to large here.

-
Also note that the order in which the options to includegraphics are used is important---i.e., set your margins after the width and height and the keepaspectratio. I was too slow to figure that one out to post the answer before @martin-scharrer:-) –  ArTourter Jan 4 '13 at 21:25
@ArTourter: The order-sensitivity is intentionally. You can e.g. first add a border and then resize if you want so. –  Martin Scharrer Jan 4 '13 at 21:28
I know that and it makes sense but I had not tweaked to it. I did not see it mention explicitly in the docs so I thought I'd mention it here since I encountered it. –  ArTourter Jan 4 '13 at 21:48
Thank you for your answer. Now I understand the usage of the export function of adjustbox. Your solution works great! I have two more questions: 1) According to your post, the \\[.8cm] don't define the row height, they define whitespace at the bottom of a row? Because it was my intention to define the row height with this code. 2) Do I still need \\[.8cm] if I write margin=.8cm .8cm? Or does margin=.8cm .8cm set the right/left margin to .8cm and not the top/bottom? –  Flying Rocket Jan 4 '13 at 22:00
@FlyingRocket: just check the description of margin in the adjustbox content. As said, \\[.8cm] will add additional vertical space after the row, not set the height. –  Martin Scharrer Jan 4 '13 at 22:57