[Tex/LaTex] Vertically center cells of a table

horizontal alignmenttablesvertical alignment

What is the easiest way to center align each row of table? I have a table column that contains an image and other cells in the same row contain text. I would like to know how to vertically center align the image and text cells. Currently each row is vertically bottom aligned. Here is my code:

\documentclass[a4paper]{article}
\usepackage[margin=1.0in]{geometry}
\usepackage{booktabs, caption, underscore, url, graphicx}
\captionsetup{font=bf}
\date{2012-03-01}
\begin{document}
\begin{table}[ht]
\centering

\begin{tabular}{cccc} \bottomrule[2pt]
A & B & V & D & E \\ \bottomrule
\includegraphics[scale=0.35]{img1.eps} & 2 & 3 & 4 \\ 
\includegraphics[scale=0.35]{img2.eps} & 2 & 3 & 4  \\ 
\bottomrule[2pt]
\end{tabular}

\end{table}
\end{document}

Here is a quick sketch of the table I am trying to achieve:

enter image description here

The first column contains an image while the other columns contain a single line of text. How can the text be center aligned with the middle of the image?

Best Answer

Vertically centering cell entries is possible via the m{<width>} column type from the array package. Horizontal centering is obtained by prepending the column entries with \centering\arraybackslash (also supported by array). For completeness and brevity, the MWE below defines the new column type M which does all of the above:

enter image description here

\documentclass[a4paper]{article}
%\usepackage{showframe}% http://ctan.org/pkg/showframe
\usepackage[margin=1.0in]{geometry}% http://ctan.org/pkg/margin
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{array}% http://ctan.org/pkg/array
\newcolumntype{M}{>{\centering\arraybackslash}m{\dimexpr.25\linewidth-2\tabcolsep}}
\begin{document}
\begin{table}[ht]
  \centering
  \begin{tabular}{MMMM}
    \toprule
    A & B & D & E \\
    \midrule
    \rule{15pt}{10pt} & One & Two & Three \\ 
    \rule{15pt}{10pt} & Three & One & Two \\ 
    \rule{15pt}{10pt} & Two & Three & One \\ 
    \bottomrule
  \end{tabular}
\end{table}
\end{document}‚Äč

For images, I've used \rule{15pt}{10pt}, although the above solution works for any image size.

The table width is also chosen to fit exactly within the text block, making each of the four columns the same width (.25\linewidth-2\tabcolsep). To see this, uncomment the showframe package which highlights the text block boundary.