GeneralCombined vertical and horizontal centering in table?

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
daviddoria
Posts: 60
Joined: Tue Sep 30, 2008 9:24 pm

Combined vertical and horizontal centering in table?

Post by daviddoria »

To get a horizontally centered column, you can use the 'c' column type. To get a vertically centered column, I saw to use the 'm' column type provided by the 'array' package (how do you know the width value to specify for this type??)

It won't let me combine to make a column of type 'mc' - is there an easy way to make the text centered in the column cell?

Here is an example: the commented line can replace the other 'tabular' line to flip-flop the vert/horiz centering.

Code: Select all

\documentclass[10pt]{article}
\usepackage{graphicx}
\usepackage{array}

\begin{document}

\begin{table}[h]
	\centering
	\begin{tabular}{c|c|c|c|c}
%\begin{tabular}{m{1in}|m{1in}|m{1in}|m{1in}|m{1in}}

		Position & ICP Mean Distance & Confidence & Consistency & Image\\ \hline
		Correct & 0.057 & 0.579 & 0.589 & \fbox{\rule{0pt}{2in} \rule{0.3\linewidth}{0pt}} \\ \hline
		Incorrect & 0.094 & 0.252 & 0.077 & \fbox{\rule{0pt}{2in} \rule{0.3\linewidth}{0pt}}\\ \hline
	\end{tabular}
	\caption{Test.}
	\label{tbl:2carsValues}
\end{table}


\end{document}

Thanks,

Dave

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Combined vertical and horizontal centering in table?

Post by gmedina »

Hi,

you can use something like

Code: Select all

>{\centering\arraybackslash}m{1in}
in the declaration of the table format.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
daviddoria
Posts: 60
Joined: Tue Sep 30, 2008 9:24 pm

Combined vertical and horizontal centering in table?

Post by daviddoria »

Great - this did it:

Code: Select all

\documentclass[10pt]{article}
\usepackage{graphicx}
\usepackage{array}

\begin{document}

\begin{table}[h]
	\centering
%	\begin{tabular}{c|c|c|c|c}
%\begin{tabular}{m{1in}|m{1in}|m{1in}|m{1in}|m{1in}}
\begin{tabular}{>{\centering\arraybackslash}m{.1\linewidth}|>{\centering\arraybackslash}m{.1\linewidth}|>{\centering\arraybackslash}m{.1\linewidth}|>{\centering\arraybackslash}m{.1\linewidth}|>{\centering\arraybackslash}m{.6\linewidth}}

		Position & ICP Mean Distance & Confidence & Consistency & Image\\ \hline
		Correct & 0.057 & 0.579 & 0.589 & \fbox{\rule{0pt}{2in} \rule{2in}{0pt}} \\ \hline
		Incorrect & 0.094 & 0.252 & 0.077 & \fbox{\rule{0pt}{2in} \rule{2in}{0pt}}\\ \hline
	\end{tabular}
	\caption{Test.}
	\label{tbl:2carsValues}
\end{table}


\end{document}


Thanks,
Dave
Post Reply