表格中列居中并调整宽度

表格中列居中并调整宽度

我有一张表格,我想让所有内容居中,但是当我使用多列时,单词不居中,并且最后两列的宽度不同。下图显示了结果。

在此处输入图片描述

我使用的代码是:

\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}

相关内容