如何更正我的 .tex 文件的格式?

huangapple go评论94阅读模式
英文:

How do I correct the formatting of my .tex file?

问题

\documentclass{standalone}
\usepackage{booktabs}
\usepackage{multirow}

\begin{document}

\begin{tabular}{l*{7}{c}} 
\toprule
& \multirow{3}{3cm}{Migration} & \multirow{3}{3cm}{No. of migrants} & \multirow{3}{3cm}{Duration} & \multirow{3}{3cm}{Migrates to Kolkata} & \multirow{3}{3cm}{Migrates to urban area} & \multirow{3}{3cm}{Earnings of migrant worker, typical month} & \multirow{3}{3cm}{Working in business} \\
\cmidrule{2-8}
& \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{7}{c}{\textit{A: Endline 1 (18 months)}} \\
\cmidrule{2-8}
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)\\
Control Mean & 0.35 & 0.39 & 37.08 & 0.36 & 0.83 & 139.89 & 0.10\\
Observations & 814 & 814 & 285 & 285 & 285 & 285 & 285\\
& \multicolumn{7}{c}{\textit{B: Endline 2 (3 years)}} \\
\cmidrule{2-8}
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)\\
Control Mean & 0.29 & 0.33 & 125.09 & 0.38 & 0.83 & 231.18 & 0.15\\
Observations & 840 & 840 & 256 & 256 & 256 & 256 & 256\\
& \multicolumn{7}{c}{\textit{C: Endline 3 (7 years)}} \\
\cmidrule{2-8}
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)\\
Control Mean & 0.37 & 0.46 & 123.26 & 0.30 & 0.78 & 361.21 & 0.11\\
Observations & 844 & 844 & 332 & 332 & 332 & 332 & 332\\
& \multicolumn{7}{c}{\textit{D: Endline 4 (10 years)}} \\
\cmidrule{2-8}
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)\\
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
\end{tabular}

\end{document}
英文:

Please tweak the following Latex code to produce the exact table attached as an image below. My current code is almost perfect, except the panel name rows are too far left and all column names have 33cm written next to them. Thank you.

\documentclass{standalone}
\usepackage{booktabs}
\begin{document}

{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}      \begin{tabular}{l*{7}{>{\centering \arraybackslash}m{3cm}}@{}} \toprule       \addlinespace[3mm]        & \multirow{3}{3cm}{Migration} & \multirow{3}{3cm}{No. of migrants} & \multirow{3}{3cm}{Duration} & \multirow{3}{3cm}{Migrates to Kolkata} & \multirow{3}{3cm}{Migrates to urban area} & \multirow{3}{3cm}{Earnings of migrant worker, typical month} & \multirow{3}{3cm}{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{7}{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{7}{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{7}{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{7}{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\\
\hline \hline \\                 \end{tabular} \\                 } 

\end{document}

The correct table is attached for reference. 如何更正我的 .tex 文件的格式?

答案1

得分: 1

你的代码未能编译,因为缺少arraymultirow宏包。不过,实际上,你的标题部分不需要multirow,所以你可以移除它而不是添加这个宏包。

如果你希望"A: Endline 1 (18 months)"等行左对齐,使用l列而不是居中的c列。

下面是你的代码的翻译:

\documentclass{standalone}
\usepackage{booktabs}
\usepackage{array}
%\usepackage{multirow}
\begin{document}

{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}      \begin{tabular}{l*{7}{>{\centering\arraybackslash}m{3cm}}@{}} \toprule       \addlinespace[3mm]        & Migration & No. of migrants & Duration & Migrates to Kolkata & Migrates to urban area & Earnings of migrant worker, typical month & Working in business \\ 
&\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}{l}{\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}{l}{\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}{l}{\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}{l}{\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\\
\hline \hline \\                 \end{tabular} \\                 } 

\end{document}

希望这可以帮助你。

英文:
  • your code did not compile because the array and multirow packages were missing. However you don't actually need multirows in your headline anyway, so you could remove those instead of adding the package.

  • if you want the A: Endline 1 (18 months) etc. lines to be on the left, use an l column and not a centred c column

\documentclass{standalone}
\usepackage{booktabs}
\usepackage{array}
%\usepackage{multirow}
\begin{document}
{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}      \begin{tabular}{l*{7}{>{\centering\arraybackslash}m{3cm}}@{}} \toprule       \addlinespace[3mm]        & Migration & No. of migrants & Duration & Migrates to Kolkata & Migrates to urban area & Earnings of migrant worker, typical month & Working in business \\ 
&\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}{l}{\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}{l}{\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}{l}{\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}{l}{\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\\
\hline \hline \\                 \end{tabular} \\                 } 
\end{document}

如何更正我的 .tex 文件的格式?

The same on overleaf: https://www.overleaf.com/read/tnttnbnhgmhc

huangapple
  • 本文由 发表于 2023年3月1日 16:36:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/75601260.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定