使用tabularx包适配表格的列宽问题求助:让3-8列数值单元格等宽
解决tabularx表格适配textwidth及列宽统一问题
你的问题出在tabularx列格式的错误使用以及multicolumn对列宽的干扰上,以下是具体解决方案:
核心问题分析
- 你尝试的
l{0.11\textwidth}写法不符合tabularx语法,该包的标准列类型为l/c/r/X,固定宽度列需通过p{宽度}或自定义列类型实现。 - 未处理multicolumn与固定列宽的匹配,跨列内容破坏了预设的列宽分配逻辑。
解决方案
方法1:自定义固定宽度居中列(精确控制宽度)
先定义居中的固定宽度列类型,再计算第3-8列的统一宽度,确保总宽度适配\textwidth:
\documentclass{article} \usepackage{tabularx,booktabs} % 定义居中的固定宽度列 \newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}} \begin{document} \begin{table*}[!t] \caption{CRAGE模型与现有模型在SEED和SEED-IV数据集三种标注方案下的平均准确率±标准差(%)对比,最优结果已加粗标注。}\label{table_1} \footnotesize % 直接用命令简化代码 \centering % 计算第3-8列的统一宽度:(总宽度-前两列宽度)/6,前两列宽度可按需调整 \newlength{\colwidth} \setlength{\colwidth}{\dimexpr(\textwidth - 2*0.15\textwidth)/6\relax} \begin{tabularx}{\textwidth}{C{0.15\textwidth}C{0.15\textwidth}*{6}{C{\colwidth}}} \toprule & & \multicolumn{3}{C{\dimexpr3*\colwidth\relax}}{SEED} & \multicolumn{3}{C{\dimexpr3*\colwidth\relax}}{SEED-\uppercase\expandafter{\romannumeral4}} \\ \cmidrule(lr){3-5} \cmidrule(lr){6-8} % 去掉线条两端延伸,提升整洁度 & & \multicolumn{6}{C{\dimexpr6*\colwidth\relax}}{标注样本数/总样本数(%)} \\ \cmidrule(lr){3-8} Scheme& Method & \multicolumn{3}{C{\dimexpr3*\colwidth\relax}}{---} & 851 / 1683 & 851 / 1673 & 832 / 1654 \\ \midrule cross session\footnotemark & name & \multicolumn{3}{C{\dimexpr3*\colwidth\relax}}{---} & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 \\ cross session & name & \multicolumn{3}{C{\dimexpr3*\colwidth\relax}}{---} & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 \\ cross session & name & \multicolumn{3}{C{\dimexpr3*\colwidth\relax}}{---} & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 \\ cross session & name & \multicolumn{3}{C{\dimexpr3*\colwidth\relax}}{---} & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 \\ cross session & name & \multicolumn{3}{C{\dimexpr3*\colwidth\relax}}{---} & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 \\ \midrule Scheme& Method & 180 / 10182 & 270 / 10182 & 360 / 10182 & 60 / 2505 & 80 / 2505 & 100 / 2505 \\ \midrule random balance & name & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 \\ random balance & name & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 \\ random balance & name & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 \\ random balance & name & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 \\ random balance & name & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 \\ random balance & name & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 \\ \bottomrule \end{tabularx} \end{table*} \footnotetext{跨会话方案中,一个会话(Ses.)的样本全标注,与另一个会话的无标注样本混合用于半监督学习。仅在SEED-IV数据集上设置三种实验场景:Ses.1(标注)/(Ses.1+Ses.2)、Ses.1(标注)/(Ses.1+Ses.3)、Ses.2(标注)/(Ses.2+Ses.3)。} \end{document}
方法2:使用tabularx的X列自动平分宽度(更简便)
利用tabularx的X列特性,让第3-8列自动平分剩余宽度,同时设置居中对齐:
\documentclass{article} \usepackage{tabularx,booktabs} % 定义居中的X列 \newcolumntype{Y}{>{\centering\arraybackslash}X} \begin{document} \begin{table*}[!t] \caption{CRAGE模型与现有模型在SEED和SEED-IV数据集三种标注方案下的平均准确率±标准差(%)对比,最优结果已加粗标注。}\label{table_1} \footnotesize \centering \begin{tabularx}{\textwidth}{ll*{6}{Y}} \toprule & & \multicolumn{3}{c}{SEED} & \multicolumn{3}{c}{SEED-\uppercase\expandafter{\romannumeral4}} \\ \cmidrule(lr){3-5} \cmidrule(lr){6-8} & & \multicolumn{6}{c}{标注样本数/总样本数(%)} \\ \cmidrule(lr){3-8} Scheme& Method & \multicolumn{3}{c}{---} & 851 / 1683 & 851 / 1673 & 832 / 1654 \\ \midrule cross session\footnotemark & name & \multicolumn{3}{c}{---} & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 \\ cross session & name & \multicolumn{3}{c}{---} & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 \\ cross session & name & \multicolumn{3}{c}{---} & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 \\ cross session & name & \multicolumn{3}{c}{---} & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 \\ cross session & name & \multicolumn{3}{c}{---} & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 \\ \midrule Scheme& Method & 180 / 10182 & 270 / 10182 & 360 / 10182 & 60 / 2505 & 80 / 2505 & 100 / 2505 \\ \midrule random balance & name & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 \\ random balance & name & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 \\ random balance & name & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 \\ random balance & name & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 \\ random balance & name & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 \\ random balance & name & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 & 40.94 $\pm$ 8.41 \\ \bottomrule \end{tabularx} \end{table*} \footnotetext{跨会话方案中,一个会话(Ses.)的样本全标注,与另一个会话的无标注样本混合用于半监督学习。仅在SEED-IV数据集上设置三种实验场景:Ses.1(标注)/(Ses.1+Ses.2)、Ses.1(标注)/(Ses.1+Ses.3)、Ses.2(标注)/(Ses.2+Ses.3)。} \end{document}
关键修改点说明
- 自定义列类型:通过
\newcolumntype定义居中列,确保数值列对齐一致。 - multicolumn宽度匹配:方法1中用
\dimexpr3*\colwidth\relax设置跨列宽度,与对应列总宽度保持一致,避免布局混乱。 - 优化表格线条:
\cmidrule(lr)去掉线条两端延伸,提升表格整洁度。 - 简化代码结构:用
\footnotesize命令代替环境包裹,减少冗余代码。
内容的提问来源于stack exchange,提问作者Daehyeon Kim
相关产品推荐
相关产品推荐

