LaTeX表格multicolumn内容未居中且留白过多问题求助
解决表格multicolumn区域留白问题的方案
你的表格留白问题主要来自空的multicolumn占位、列数标注错误、语法格式疏漏这几个点,以下是针对性的修正方案:
核心问题分析
- 原代码中
\multicolumn{2}{c}{}是空占位,直接导致中间区域出现大片留白; - 注释标注7列,但实际是8列,列格式定义和实际内容不匹配;
- 用了编程语言的
\n而非LaTeX的换行符\\,且ROC_AUC(\%) PR_AUC(\%)之间缺少列分隔符&,导致列错位。
基础修正版(保留原竖线风格)
\begin{table*} \caption{Different sampling strategies and the corresponding PRF scores, explain the scores!} \label{table:PRF_scores} \centering \begin{tabular}{c c | c c | c c c c } % 修正为实际的8列 \hline\hline \multicolumn{2}{c|}{\emph{sampling strategy}} & \multicolumn{2}{c|}{\emph{sample size}} & % 给中间两列添加标题,替换空占位 \multicolumn{4}{c}{\emph{performance metrics}} \\ under\_sample & over\_sample & $N_{\text{memb}}$ & $N_{\text{non-memb}}$ & F1(\%) & ROC\_AUC(\%) & PR\_AUC(\%) & MCC(\%) \\ \hline 0.5 & 1.0 & 752 & 752 & 98.54 $\pm$ 0.62 & 98.62 $\pm$ 0.64 & 98.62 $\pm$ 0.59 & 97.08 $\pm$ 1.25 \\ 0.1 & 1.0 & 3760 & 3760 & 99.09 $\pm$ 0.17 & 99.08 $\pm$ 0.18 & 99.09 $\pm$ 0.17 & 98.17 $\pm$ 0.35 \\ 0.06 & 0.6 & 3759 & 6266 & 98.68 $\pm$ 0.23 & 99.19 $\pm$ 0.15 & 98.70 $\pm$ 0.23 & 97.89 $\pm$ 0.37 \\ \hline \end{tabular} \end{table*}
关键修改点
- 给中间两列新增
sample size分组标题,彻底消除空占位带来的留白; - 修正列数定义,匹配实际8列内容;
- 替换
\n为LaTeX标准换行符\\,补全ROC_AUC(\%)与PR_AUC(\%)之间的&分隔符; - 优化下标格式为
$N_{\text{memb}}$,让文本下标更规范(需导入amsmath包,或用$N_{\rm memb}$替代)。
进阶美观版(使用booktabs包)
如果想要更专业简洁的表格样式,推荐使用booktabs包去掉竖线,用分层横线替代:
% 导言区先添加包 \usepackage{booktabs} \usepackage{amsmath} % 支持\text{}命令 \begin{table*} \caption{Different sampling strategies and the corresponding PRF scores, explain the scores!} \label{table:PRF_scores} \centering \begin{tabular}{cccccccc} \toprule \multicolumn{2}{c}{\emph{sampling strategy}} & \multicolumn{2}{c}{\emph{sample size}} & \multicolumn{4}{c}{\emph{performance metrics}} \\ \cmidrule(lr){1-2} \cmidrule(lr){3-4} \cmidrule(lr){5-8} % 给每个分组添加局部横线 under\_sample & over\_sample & $N_{\text{memb}}$ & $N_{\text{non-memb}}$ & F1(\%) & ROC\_AUC(\%) & PR\_AUC(\%) & MCC(\%) \\ \midrule 0.5 & 1.0 & 752 & 752 & 98.54 $\pm$ 0.62 & 98.62 $\pm$ 0.64 & 98.62 $\pm$ 0.59 & 97.08 $\pm$ 1.25 \\ 0.1 & 1.0 & 3760 & 3760 & 99.09 $\pm$ 0.17 & 99.08 $\pm$ 0.18 & 99.09 $\pm$ 0.17 & 98.17 $\pm$ 0.35 \\ 0.06 & 0.6 & 3759 & 6266 & 98.68 $\pm$ 0.23 & 99.19 $\pm$ 0.15 & 98.70 $\pm$ 0.23 & 97.89 $\pm$ 0.37 \\ \bottomrule \end{tabular} \end{table*}
这个版本的表格没有冗余竖线,分层横线更符合学术排版规范,同时完全解决留白问题。
内容的提问来源于stack exchange,提问作者Barbarosso027
相关产品推荐
相关产品推荐

