如何在 tabularx 中调整这个多列的表格?

如何在 tabularx 中调整这个多列的表格?

我正在尝试使用多列和 tabularx 创建正确的表格。这是我的代码

\documentclass{article}
\usepackage{booktabs}
\usepackage{tabularx}
\begin{document}



\begin{table}[!htbp]
    \centering
    \begin{tabularx}{\textwidth}{lXXXXX}
        \toprule
        \multicolumn{2}{c}{obs}&\multicolumn{2}{c}{RES 30}
        &
        \multicolumn{2}{c}{RES 100} \\\cmidrule(r){3-4}\cmidrule(l){5-6}
        && RMSE& $R^2$ & RMSE & $R^2$\\
        \multicolumn{1}{c}{}\\\cmidrule(r){3-4}\cmidrule(l){5-6}
        Cluster 1   &44&5.39&0.36 &5.57&0.31\\
        Cluster 2   &17&6.83&0.34&5.69&0.42\\
        Cluster 3   &107&5.58&0.66&6.40&0.21\\
        Pistoia     & 80 &6.44& 0.41&6.44& 0.66\\
        \bottomrule
    \end{tabularx}
    \caption{Validation results for simulated and observed average of R median.}
    \label{tab:results_BNs}
\end{table}

\end{document}

obs 应该保持在 44 以上

谢谢你!

答案1

与 David Carlisle 之前评论中的建议类似,以下是表格的两个可能版本。为了将其obs作为标题放置在第二列,我删除了\multicolumn{2}它周围的命令并添加了一个&。此外,我已使用siunitx对齐数字与小数点标记并删除了列标题中的空行。

在此处输入图片描述

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}

\begin{table}[!htbp]
    \centering
    \begin{tabular}{lS[table-format=3]*{4}{S[table-format=1.2]}}
        \toprule
       & obs &\multicolumn{2}{c}{RES 30}
        &
        \multicolumn{2}{c}{RES 100} \\\cmidrule(r){3-4}\cmidrule(l){5-6}
        && {RMSE}& {$R^2$} & {RMSE} & {$R^2$}\\
        \cmidrule(r){3-4}\cmidrule(l){5-6}
        Cluster 1   &44&5.39&0.36 &5.57&0.31\\
        Cluster 2   &17&6.83&0.34&5.69&0.42\\
        Cluster 3   &107&5.58&0.66&6.40&0.21\\
        Pistoia     & 80 &6.44& 0.41&6.44& 0.66\\
        \bottomrule
    \end{tabular}
    \caption{Validation results for simulated and observed average of R median.}
    \label{tab:results_BNs}
\end{table}

\begin{table}[!htbp]
    \centering
    \begin{tabular}{lS[table-format=3]*{4}{S[table-format=1.2]}}
        \toprule
       & &\multicolumn{2}{c}{RES 30}
        &
        \multicolumn{2}{c}{RES 100} \\\cmidrule(r){3-4}\cmidrule(l){5-6}
        &obs & {RMSE}& {$R^2$} & {RMSE} & {$R^2$}\\
        \cmidrule(r){3-4}\cmidrule(l){5-6}
        Cluster 1   &44&5.39&0.36 &5.57&0.31\\
        Cluster 2   &17&6.83&0.34&5.69&0.42\\
        Cluster 3   &107&5.58&0.66&6.40&0.21\\
        Pistoia     & 80 &6.44& 0.41&6.44& 0.66\\
        \bottomrule
    \end{tabular}
    \caption{Validation results for simulated and observed average of R median.}
    \label{tab:results_BNs}
\end{table}

\end{document}

相关内容