我现在正在制作一张桌子,我真的很想把它居中,让它看起来更整洁。唯一的问题是,在我导入数组包,然后使用 m{width} 函数之后。它似乎什么也没做。知道为什么吗?这是表格的代码和图片。
此外,还有这些错误标记,它们都与下面代码中突出显示的错误标记相同。这些是什么意思,我一直在试图弄清楚,但似乎找不到解决方案。
\begin{table}[htpb]
\centering
\begin{tabular}{m{2.5cm}|m{2.5cm}p{2.5cm}p{2.5cm}p{2.5cm}}
\multicolumn{2}{l}{\textbf{Reduced data}} \\ \cline{1-2}
{} & Average Mass [kg]$\pm$0.0001 & Average Radius [m]$\pm$0.00001 & Experimental Height [m]$\pm$0.00305 & Theoretical Height [m]\\
\hline
Ball Type & & & & \\ \hline
Table Tennis & 0.00248 & 0.01871 & 0.24831 & 0.34973 $\pm$0.00519 \\
Racquet & 0.04172 & 0.02803 & 0.51206 & 0.70837 $\pm$0.00787 \\
Squash & 0.02382 & 0.01978 & 0.09103 & 0.12059 $\pm$0.01629 \\
\end{tabular}
\end{table}
-谢谢
答案1
稍微修改了 AboAmmar 的答案...借助makecell
用于将列标题设置为两行的包,您可以获得:
\documentclass[a4paper,12pt]{article}
\usepackage{booktabs,makecell}
\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{l*{4}{c}}
\toprule
& \multicolumn{4}{c}{\textbf{Reduced data}} \\
\cmidrule{2-5}
& \thead{Average Mass\\ {[kg]$\pm$0.0001}}
& \thead{Average Radius\\ {[m]$\pm$0.00001}}
& \thead{Experimental Height\\ {[m]$\pm$0.00305}}
& \thead{Theoretical Height\\ {[m]}}\\
\hline
Ball Type & & & & \\
\midrule
Table Tennis & 0.00248 & 0.01871 & 0.24831 & 0.34973 $\pm$0.00519 \\
Racquet & 0.04172 & 0.02803 & 0.51206 & 0.70837 $\pm$0.00787 \\
Squash & 0.02382 & 0.01978 & 0.09103 & 0.12059 $\pm$0.01629 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
如果您希望列标题的字体大小与整个表格相同,那么您需要在序言中添加(加载makecell
包后):
\renewcommand\theadfont{\normalsize}
编辑: 和版本,如果您喜欢将列标题设置为三行并合并第二行和第三行表格:
\documentclass[a4paper,12pt]{article}
\usepackage{booktabs,makecell}
\renewcommand\theadfont{\normalsize}
\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{l*{4}{c}}
\toprule
& \multicolumn{4}{c}{\textbf{Reduced data}} \\
\cmidrule{2-5}
\thead{~\\~\\ \textbf{Ball Type}}
& \thead{Average\\ Mass\\ {[kg]$\pm$0.0001}}
& \thead{Average\\ Radius\\ {[m]$\pm$0.00001}}
& \thead{Experimental\\ Height\\ {[m]$\pm$0.00305}}
& \thead{Theoretical\\ Height\\ {[m]}}\\
\midrule
Table Tennis & 0.00248 & 0.01871 & 0.24831 & 0.34973 $\pm$0.00519 \\
Racquet & 0.04172 & 0.02803 & 0.51206 & 0.70837 $\pm$0.00787 \\
Squash & 0.02382 & 0.01978 & 0.09103 & 0.12059 $\pm$0.01629 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
\documentclass{article}
\usepackage{graphicx,amsmath,booktabs}
\begin{document}
\begin{table}[htpb]
\centering\small
\begin{tabular}{l*{4}c}
\toprule
&\multicolumn{4}{c}{\textbf{Reduced data}} \\ \cmidrule{2-5}
& Average & Average & Experimental & Theoretical \\
& Mass [kg] & Radius [m]& Height [m] & Height [m] \\
\textbf{Ball Type} & $\pm$0.0001 & $\pm$0.00001 & $\pm$0.00305 & \\ \midrule
Table Tennis & 0.00248 & 0.01871 & 0.24831 & 0.34973 $\pm$0.00519 \\
Racquet & 0.04172 & 0.02803 & 0.51206 & 0.70837 $\pm$0.00787 \\
Squash & 0.02382 & 0.01978 & 0.09103 & 0.12059 $\pm$0.01629 \\ \bottomrule
\end{tabular}
\end{table}
\end{document}
答案3
目前向您的代码添加一个新的列类型。
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}} % zentriert mit Breitenangabe
否则提供 MWE。