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:
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 thearray
package. Horizontal centering is obtained by prepending the column entries with\centering\arraybackslash
(also supported byarray
). For completeness and brevity, the MWE below defines the new column typeM
which does all of the above: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 theshowframe
package which highlights the text block boundary.