我怎样才能使此代码中的列值居中?
\documentclass[conference]{IEEEtran}
\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}
答案1
您必须加载包array
,定义一个具有水平居中的新列类型
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
并使用这个(P
)代替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}
输出:
如果您还想要垂直居中,请m
使用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}
输出:
答案2
如果列的宽度没有预先定义,最简单的解决方案是c
使用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}
输出:
答案3
一个非常简单的解决方案似乎有效!
使用tabular
和p{...}
并在单元格文本前添加\hfil
。看起来文本变得居中了!例如:
\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}
答案4
对我来说,只使用 \hfil 后跟文本就可以了
\begin{center}
\begin{tabular}{ |p{5cm}|p{3cm}|p{3cm}|p{3cm}| }
\hline
\multicolumn{4}{|c|}{Comparison table} \\
\hline
Features & \hfil TreeMind & \hfil Calm & \hfil Headspace \\
\hline
Breathing exercises & \hfil \checkmark & \hfil \checkmark & \hfil \checkmark \\
Meditation courses & \hfil \checkmark & \hfil \checkmark & \hfil \checkmark \\
User's Feedback & \hfil \checkmark & \hfil \checkmark & \hfil \checkmark \\
Virtual trainer & \hfil \checkmark & \hfil \checkmark & \hfil \checkmark \\
Sleep stories & \hfil \checkmark & \hfil \checkmark & \hfil \checkmark \\
\hline
\end{tabular}
\end{center}