[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:

\usepackage{booktabs, caption, underscore, url, graphicx}

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


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

%\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
    A & B & D & E \\
    \rule{15pt}{10pt} & One & Two & Three \\ 
    \rule{15pt}{10pt} & Three & One & Two \\ 
    \rule{15pt}{10pt} & Two & Three & One \\ 

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.