![表格中列居中并调整宽度](https://linux22.com/image/335961/%E8%A1%A8%E6%A0%BC%E4%B8%AD%E5%88%97%E5%B1%85%E4%B8%AD%E5%B9%B6%E8%B0%83%E6%95%B4%E5%AE%BD%E5%BA%A6.png)
我有一张表格,我想让所有内容居中,但是当我使用多列时,单词不居中,并且最后两列的宽度不同。下图显示了结果。
我使用的代码是:
\documentclass[10pt,a4paper]{report}
\usepackage{booktabs}
\usepackage{multirow}
\begin{document}
\begin{table}[!h]
\renewcommand{\arraystretch}{1.2} % more space between rows
\centering
\caption{Particle average size obtained via TEM analysis.}
\begin{tabular}{c|c|c|c}
\toprule
\multirow{2}{*}{Sample}& \multirow{2}{*}{Morphology} & \multicolumn{2}{c}{Particle average size (nm)} \\ \cline{3-4}
& & Diameter & Length \\
\midrule
Pr-100-300-60 & & & \\
W-100-400-30 & & & \\
W-75-400-30 & & & \\
W-50-400-30 & & & \\
W-25-400-30 & & & \\
W-0-400-30 & & & \\ \bottomrule
\end{tabular}
\label{tab:TEM}
\end{table}
\end{document}
那么,我可以将列宽设置为相等,并将“粒子平均尺寸(纳米)”字样居中吗?谢谢您的帮助
答案1
使用 tabularx 包。避免使用垂直线。
\documentclass[10pt,a4paper]{report}
\usepackage{booktabs}
\usepackage{multirow, tabularx,array}
\begin{document}
\begin{table}[!h]
%\renewcommand{\arraystretch}{1.2} % more space between rows
\centering
\caption{Particle average size obtained via TEM analysis.}
\begin{tabularx}{0.75\textwidth}{cc *2{>{\centering\arraybackslash}X}}
\toprule
\multirow{2}{*}{Sample}& \multirow{2}{*}{Morphology} & \multicolumn{2}{c}{Particle average size (nm)} \\ \cmidrule(lr){3-4}
& & Diameter & Length \\
\midrule
Pr-100-300-60 & & & \\
W-100-400-30 & & & \\
W-75-400-30 & & & \\
W-50-400-30 & & & \\
W-25-400-30 & & & \\
W-0-400-30 & & & \\ \bottomrule
\end{tabularx}
\label{tab:TEM}
\end{table}
\end{document}