How to center column values in a table?
You have to load the package array
, define a new column type with horizontal centering
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
and use this one (P
) instead of p
\documentclass[conference]{IEEEtran}
\usepackage{array}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\begin{document}
\begin{table}
\centering
\begin{tabular}{|P{2.5cm}|P{2.5cm}|P{2.5cm}|}
\hline
Reconstruction strategy & aa & bb( \%) \\ \hline
Classic & 3342 voxels & 68 \% \\ \hline
VC & 4296 voxels & 87 \% \\ \hline
V m=7 & 4745 voxels & 96 \% \\ \hline
\end{tabular}
\newline\newline
\caption{title}\label{tab1}
\end{table}
\end{document}
Output:
If you also want vertical centering, use m
instead of p
:
\documentclass[conference]{IEEEtran}
\usepackage{array}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\begin{document}
\begin{table}
\centering
\begin{tabular}{|M{2.5cm}|M{2.5cm}|M{2.5cm}|}
\hline
Reconstruction strategy & aa & bb( \%) \\ \hline
Classic & 3342 voxels & 68 \% \\ \hline
VC & 4296 voxels & 87 \% \\ \hline
V m=7 & 4745 voxels & 96 \% \\ \hline
\end{tabular}
\newline\newline
\caption{title}\label{tab1}
\end{table}
\end{document}
Output:
If the width of the columns is not predefined, the most simple solution is to use c
instead of p
:
\documentclass[conference]{IEEEtran}
\begin{document}
\begin{table}
\centering
\begin{tabular}{|c|c|c|}
\hline
Reconstruction strategy & aa & bb( \%) \\ \hline
Classic & 3342 voxels & 68 \% \\ \hline
VC & 4296 voxels & 87 \% \\ \hline
V m=7 & 4745 voxels & 96 \% \\ \hline
\end{tabular}
\newline\newline
\caption{title}\label{tab1}
\end{table}
\end{document}
Output:
A very simple solution seems to work!
use tabular
and p{...}
and add \hfil
before cell text. it seems that the text become centered! as an example:
\begin{table}
\begin{center}
\begin{tabular}{c|p{2.5cm}|p{2.5cm}}
\multirow{2}{*} {something in multirow} & \multicolumn{2}{c}{another in multicolumn} \\
& \hfil$Q in kg/s$ & \hfil$Q in m^3/s$ \\
\hline
first & \hfil7.3 & \hfil inf \\
second & \hfil3.2 & \hfil0.5 \\
third & \hfil inf & \hfil0 \\
\end{tabular}
\end{center}
\end{table}