You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修正.tex文件格式并调整LaTeX表格的排版问题

LaTeX表格问题修正方案

问题分析与解决步骤

1. 面板名称行靠左的问题

原代码中面板标题使用\multicolumn{7}{c},但表格实际包含8列(1个左对齐列+7个数据列),跨7列会导致标题无法完全居中。改为\multicolumn{8}{c}即可让标题居中显示。

2. 列名称旁显示3cm字样的问题

  • 原代码未加载array包,导致>{\centering \arraybackslash}这种列格式修饰符无法被识别,被当作文本输出
  • 代码中存在HTML转义字符>,LaTeX无法解析,需替换为LaTeX原生的>
  • 移除\multirow中固定的3cm宽度,改用*让内容自动适配宽度,避免不必要的宽度限制

修正后的完整代码

\documentclass{standalone}
\usepackage{booktabs}
\usepackage{array} % 新增:支持列格式修饰符
\begin{document}

{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{tabular}{l*{7}{>{\centering\arraybackslash}m{3cm}}@{}} 
\toprule
\addlinespace[3mm]
& \multirow{3}{*}{Migration} 
& \multirow{3}{*}{No. of migrants} 
& \multirow{3}{*}{Duration} 
& \multirow{3}{*}{Migrates to Kolkata} 
& \multirow{3}{*}{Migrates to urban area} 
& \multirow{3}{*}{Earnings of migrant worker, typical month} 
& \multirow{3}{*}{Working in business} \\
\addlinespace[12mm]
& \multicolumn{1}{c}{(1)} & \multicolumn{1}{c}{(2)} & \multicolumn{1}{c}{(3)} 
& \multicolumn{1}{c}{(4)} & \multicolumn{1}{c}{(5)} & \multicolumn{1}{c}{(6)} 
& \multicolumn{1}{c}{(7)} \\
\hline
\multicolumn{8}{c}{\textit{A: Endline 1 (18 months)}} \\
\addlinespace[1mm]
Treatment           & -0.015 & 0.002 & 11.767 & -0.004 & 0.002 & 26.326 & 0.042 \\
                    & (0.034)& (0.041)& (6.798)& (0.066)& (0.055)& (19.011)& (0.046)\\
[1em]
Control Mean        & 0.35   & 0.39  & 37.08  & 0.36   & 0.83  & 139.89  & 0.10 \\
Observations        & 814    & 814   & 285    & 285    & 285   & 285     & 285 \\
\addlinespace[1mm]
\multicolumn{8}{c}{\textit{B: Endline 2 (3 years)}} \\
[1em]
Treatment           & 0.029  & 0.032 & 14.776 & -0.095 & -0.039& 30.574  & 0.032 \\
                    & (0.032)& (0.041)& (15.332)& (0.069)& (0.059)& (29.920)& (0.042)\\
[1em]
Control Mean        & 0.29   & 0.33  & 125.09 & 0.38   & 0.83  & 231.18  & 0.15 \\
Observations        & 840    & 840   & 256    & 256    & 256   & 256     & 256 \\
\addlinespace[1mm]
\multicolumn{8}{c}{\textit{C: Endline 3 (7 years)}} \\
[1em]
Treatment           & 0.045  & 0.045 & -11.078& 0.067  & 0.012 & 89.788  & 0.017 \\
                    & (0.034)& (0.047)& (12.466)& (0.058)& (0.047)& (33.619)& (0.037)\\
[1em]
Control Mean        & 0.37   & 0.46  & 123.26 & 0.30   & 0.78  & 361.21  & 0.11 \\
Observations        & 844    & 844   & 332    & 332    & 332   & 332     & 332 \\
\addlinespace[1mm]
\multicolumn{8}{c}{\textit{D: Endline 4 (10 years)}} \\
[1em]
Treatment           & 0.015  & 0.022 & 25.167 & -0.138 & 0.033 & 51.238  & -0.029 \\
                    & (0.032)& (0.046)& (12.743)& (0.059)& (0.053)& (31.215)& (0.042)\\
[1em]
Control Mean        & 0.34   & 0.44  & 123.78 & 0.35   & 0.79  & 361.95  & 0.13 \\
Observations        & 861    & 861   & 308    & 309    & 309   & 309     & 309 \\
\bottomrule % 替换原有的\hline\hline,符合booktabs规范
\end{tabular}
}

\end{document}

额外优化说明

  • 使用\bottomrule替代\hline\hline,符合booktabs包的排版规范,线条更美观
  • 清理了代码中多余的空格和换行,提升代码可读性
  • \multirow改用*宽度,避免固定宽度导致的内容换行或溢出问题

内容的提问来源于stack exchange,提问作者user21006068

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 15:04:57