我刚刚学习 LaTex。我使用 stata 并得到以下结果
{
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{tabular}{l*{3}{ccc}l}
\hline
\multicolumn{11}{l}{\textit{Panel A: }} \\
\hline\hline
&\multicolumn{3}{c}{Overall} &\multicolumn{3}{c}{Set Household} &\multicolumn{3}{c}{Non-set Household} & \multicolumn{1}{l}{T-test}\\
& count& mean& sd& count& mean& sd& count& mean& sd &\\
\hline
Average Age of the household respondent & 5000& 44.7& 12.8& 3400& 44.4& 12.5& 1016& 44.9& 13.1& 0.511 \\
& & & & & & & & & & (0.87) \\
Percentage of Married & 4000& 0.86& 0.35& 345& 0.87& 0.34& 800& 0.85& 0.35& -0.014\\
& & & & & & & & & & (-0.88) \\
Number of family that are dependent in the income & 99& 0.83& 0.67& 94& 0.79& 0.70& 5000& 0.86& 0.65 & 0.070\sym{*} \\
& & & & & & & & & & (2.29) \\
\hline
\multicolumn{11}{l}{\textit{Panel B: }} \\
\hline\hline
\hline
\multicolumn{11}{l}{\textit{Panel C: }} \\
\hline\hline
\hline\hline
\multicolumn{2}{l}{\footnotesize \textit{t} statistics in parentheses}\\
\multicolumn{2}{l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
\end{tabular}
}
我后来通过 stata 生成了新表,并编辑了表格并添加了面板 B 和 C。我使用以下 tex 文件来创建我的文档,因为我有多个表格
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{array}
\usepackage{paralist}
\usepackage{verbatim}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{setspace}
\onehalfspacing
\usepackage[parfill]{parskip}
%--------------------------------------- Document --------------------------------------%
\title{\huge{}}
\author{}
\date{}
\begin{document}
\maketitle
\section*{Introduction}
\begin{table}[h]
\centering
\caption{ }
\input{d.tex}
\end{table}
\begin{table}[h]
\centering
\caption{}
\input{m.tex}
\end{table}
\end{document}
我已经尝试过以下代码
1st
\begin{tabular}{ |p{3cm}||p{3cm}|p{3cm}|p{3cm}| |p{3cm}||p{3cm}|p{3cm}|p{3cm}| |p{3cm}||p{3cm}|}
2nd
\begin{tabular}{|l*{3}{ccc}l|}
3rd
\\resizebox{\textwidth}{p{3cm}}{\begin{tabular}{l*{3}{ccc}l}
4th
\begin{tabular}{\linewidth}{l*{3}{ccc}l}
但我得到了错误和/或它没有解决我的问题并且表格仍然溢出页面。我希望这里有人能帮助我解决这个问题,我将非常感激。
答案1
这是一个带有 和 的命题makecell, multirow, booktabs
,geometry
略微减小了字体大小和列间距:
\documentclass[a4paper]{article}
\usepackage[showframe]{geometry}
\usepackage[english]{babel}
\usepackage{booktabs}
\usepackage{array, makecell, multirow}%
\usepackage{siunitx}
\usepackage{amssymb}
\usepackage{setspace}
\onehalfspacing
\usepackage[parfill]{parskip}
\begin{document}
{
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\setlength{\tabcolsep}{3pt}
\renewcommand{\theadset}{\renewcommand{\arraystretch}{0.6}}
\renewcommand{\theadalign}{lc}
\renewcommand{\theadfont}{\small}
\sisetup{table-format=2.2, table-number-alignment=center}
\small
\begin{center}
\begin{tabular}{@{}l*{3}{S[table-format=4.0]SS}S[table-format=-1.3, table-space-text-post=\sym{*}]}
\toprule
\multicolumn{11}{l}{\textit{Panel A: }} \\
\midrule\midrule
&\multicolumn{3}{c}{Overall} &\multicolumn{3}{c}{Set Household} &\multicolumn{3}{c}{Non-set Household} & {\multirowcell{2}{T-test}}\\
\cmidrule(lr){2-4}\cmidrule(r){5-7}\cmidrule(r){8-10}
& {count} & {mean} & {sd} & {count} & {mean} & {sd} & {count} & {mean} & {sd}&\\
\midrule
\multirowthead{2}{Average Age of the \\ household respondent} & 5000& 44.7& 12.8& 3400& 44.4& 12.5& 1016& 44.9& 13.1& 0.511 \\
& & & & & & & & & &{$ (0.87) $} \\
\addlinespace
\thead { Percentage of Married} & 4000& 0.86& 0.35& 345& 0.87& 0.34& 800& 0.85& 0.35& -0.014\\
& & & & & & & & & & {$ (-0.88) $} \\
\addlinespace
\multirowthead{2}{Number of families that are\\ dependent in the income} & 99& 0.83& 0.67& 94& 0.79& 0.70& 5000& 0.86& 0.65 & 0.070\sym{*} \\
& & & & & & & & & &{$ (2.29) $} \\
\addlinespace[2ex]
\midrule
\multicolumn{11}{l}{\textit{Panel B: }} \\
\midrule\midrule \\
\midrule
\multicolumn{11}{l}{\textit{Panel C: }} \\
\midrule\midrule \\
\bottomrule
\multicolumn{3}{@{}l}{\footnotesize \textit{t} statistics in parentheses}\\
\multicolumn{3}{@{}l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
\end{tabular}
\end{center}
}
\end{document}
答案2
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{array}
\usepackage{paralist}
\usepackage{verbatim}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{setspace}
\onehalfspacing
\usepackage[parfill]{parskip}
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\usepackage{siunitx} % for improved alignment of numbers in tables using the S type column
\usepackage{tabularx} % to make sure the table is as wide as the textwidth, for teh X type column
\usepackage{booktabs} % for horizontal lines with improved spacing
\usepackage{geometry} % for smaller margins, otherwise the table wouldn't fit
\usepackage{multirow} % for the multirow command
%--------------------------------------- Document --------------------------------------%
\begin{document}
\begin{table}[h]
\small
\setlength{\tabcolsep}{4pt}
\centering
\caption{ }
\begin{tabularx}{\linewidth}{@{}X
*{3}{
S[table-format=4]
S[table-format=2.2]
S[table-format=2.2]
}
S[table-format=-1.3,
input-symbols = {()},
table-space-text-pre=),
table-space-text-post=\sym{*},
table-align-text-post=false,
]@{}}
\toprule
\multicolumn{11}{@{}l@{}}{\textit{Panel A: }} \\
\midrule
& \multicolumn{3}{c}{Overall} & \multicolumn{3}{c}{Set Household} & \multicolumn{3}{c}{Non-set Household} & \multicolumn{1}{l}{T-test}\\
\cmidrule(r){2-4} \cmidrule(lr){5-7} \cmidrule(lr){8-10}
& {count} & {mean} & {sd} & {count} & {mean} & {sd} & {count} & {mean} &{sd} & \\
\midrule
\multirow[t]{2}{=}{Average Age of the household respondent}
& 5000 & 44.7 & 12.8 & 3400 & 44.4 & 12.5 & 1016 & 44.9 & 13.1 & 0.511 \\
& & & & & & & & & & (0.87) \\
Percentage of Married
& 4000 & 0.86 & 0.35 & 345 & 0.87 & 0.34 & 800 & 0.85 & 0.35 & -0.014 \\
& & & & & & & & & & {(}-0.88) \\
\multirow[t]{2}{=}{Number of family that are dependent in the income}
& 99 & 0.83 & 0.67 & 94 & 0.79 & 0.70 & 5000 & 0.86 & 0.65 & 0.070\sym{*} \\
& & & & & & & & & & (2.29) \\
\midrule
\multicolumn{11}{@{}l@{}}{\textit{Panel B: }} \\
\midrule
\midrule
\multicolumn{11}{@{}l@{}}{\textit{Panel C: }} \\
\midrule
\bottomrule
\multicolumn{11}{@{}l@{}}{\footnotesize \textit{t} statistics in parentheses}\\
\multicolumn{11}{@{}l@{}}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
\end{tabularx}
\end{table}
\end{document}
由于您在评论中提到,面板 B 和面板 C 将包含与面板 A 中的条目属于同一列的条目,因此我建议使用以下略有不同的布局版本。在这两个版本中,我都将“面板 A”放置在列标题下方,以避免在每个面板中重复它们。为了在视觉上将它们“面板 x”与周围的表格区分开来,我使用了两条水平线或缩进和小垂直空白的组合:
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{array}
\usepackage{paralist}
\usepackage{verbatim}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{setspace}
\onehalfspacing
\usepackage[parfill]{parskip}
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\usepackage{siunitx} % for improved alignment of numbers in tables using the S type column
\usepackage{tabularx} % to make sure the table is as wide as the textwidth, for teh X type column
\usepackage{booktabs} % for horizontal lines with improved spacing
\usepackage{geometry} % for smaller margins, otherwise the table wouldn't fit
\usepackage{multirow} % for the multirow command
%--------------------------------------- Document --------------------------------------%
\begin{document}
\begin{table}[h]
\small
\setlength{\tabcolsep}{4pt}
\centering
\caption{ }
\begin{tabularx}{\linewidth}{@{}X
*{3}{
S[table-format=4]
S[table-format=2.2]
S[table-format=2.2]
}
S[table-format=-1.3,
input-symbols = {()},
table-space-text-pre=),
table-space-text-post=\sym{*},
table-align-text-post=false,
]@{}}
\toprule
& \multicolumn{3}{c}{Overall} & \multicolumn{3}{c}{Set Household} & \multicolumn{3}{c}{Non-set Household} & \multicolumn{1}{l}{T-test}\\
\cmidrule(r){2-4} \cmidrule(lr){5-7} \cmidrule(lr){8-10}
& {count} & {mean} & {sd} & {count} & {mean} & {sd} & {count} & {mean} &{sd} & \\
\midrule
\multicolumn{11}{@{}l@{}}{\textit{Panel A: }} \\
\midrule
\multirow[t]{2}{=}{Average Age of the household respondent}
& 5000 & 44.7 & 12.8 & 3400 & 44.4 & 12.5 & 1016 & 44.9 & 13.1 & 0.511 \\
& & & & & & & & & & (0.87) \\
Percentage of Married
& 4000 & 0.86 & 0.35 & 345 & 0.87 & 0.34 & 800 & 0.85 & 0.35 & -0.014 \\
& & & & & & & & & & {(}-0.88) \\
\multirow[t]{2}{=}{Number of family that are dependent in the income}
& 99 & 0.83 & 0.67 & 94 & 0.79 & 0.70 & 5000 & 0.86 & 0.65 & 0.070\sym{*} \\
& & & & & & & & & & (2.29) \\
\midrule
\multicolumn{11}{@{}l@{}}{\textit{Panel B: }} \\
\midrule
\multirow[t]{2}{=}{Average Age of the household respondent}
& 5000 & 44.7 & 12.8 & 3400 & 44.4 & 12.5 & 1016 & 44.9 & 13.1 & 0.511 \\
& & & & & & & & & & (0.87) \\
Percentage of Married
& 4000 & 0.86 & 0.35 & 345 & 0.87 & 0.34 & 800 & 0.85 & 0.35 & -0.014 \\
& & & & & & & & & & {(}-0.88) \\
\midrule
\multicolumn{11}{@{}l@{}}{\textit{Panel C: }} \\
\midrule
\multirow[t]{2}{=}{Average Age of the household respondent}
& 5000 & 44.7 & 12.8 & 3400 & 44.4 & 12.5 & 1016 & 44.9 & 13.1 & 0.511 \\
& & & & & & & & & & (0.87) \\
Percentage of Married
& 4000 & 0.86 & 0.35 & 345 & 0.87 & 0.34 & 800 & 0.85 & 0.35 & -0.014 \\
& & & & & & & & & & {(}-0.88) \\
\bottomrule
\multicolumn{11}{@{}l@{}}{\footnotesize \textit{t} statistics in parentheses}\\
\multicolumn{11}{@{}l@{}}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
\end{tabularx}
\end{table}
\begin{table}[h]
\small
\setlength{\tabcolsep}{3.5pt}
\centering
\caption{ }
\begin{tabularx}{\linewidth}{X
*{3}{
S[table-format=4]
S[table-format=2.2]
S[table-format=2.2]
}
S[table-format=-1.3,
input-symbols = {()},
table-space-text-pre=),
table-space-text-post=\sym{*},
table-align-text-post=false,
]@{}}
\toprule
& \multicolumn{3}{c}{Overall} & \multicolumn{3}{c}{Set Household} & \multicolumn{3}{c}{Non-set Household} & \multicolumn{1}{l}{T-test}\\
\cmidrule(r){2-4} \cmidrule(lr){5-7} \cmidrule(lr){8-10}
& {count} & {mean} & {sd} & {count} & {mean} & {sd} & {count} & {mean} &{sd} & \\
\midrule
\multicolumn{11}{@{}l@{}}{\textit{Panel A: }} \\
\addlinespace
\multirow[t]{2}{=}{Average Age of the household respondent}
& 5000 & 44.7 & 12.8 & 3400 & 44.4 & 12.5 & 1016 & 44.9 & 13.1 & 0.511 \\
& & & & & & & & & & (0.87) \\
Percentage of Married
& 4000 & 0.86 & 0.35 & 345 & 0.87 & 0.34 & 800 & 0.85 & 0.35 & -0.014 \\
& & & & & & & & & & {(}-0.88) \\
\multirow[t]{2}{=}{Number of family that are dependent in the income}
& 99 & 0.83 & 0.67 & 94 & 0.79 & 0.70 & 5000 & 0.86 & 0.65 & 0.070\sym{*} \\
& & & & & & & & & & (2.29) \\
\midrule
\multicolumn{11}{@{}l@{}}{\textit{Panel B: }} \\
\addlinespace
\multirow[t]{2}{=}{Average Age of the household respondent}
& 5000 & 44.7 & 12.8 & 3400 & 44.4 & 12.5 & 1016 & 44.9 & 13.1 & 0.511 \\
& & & & & & & & & & (0.87) \\
Percentage of Married
& 4000 & 0.86 & 0.35 & 345 & 0.87 & 0.34 & 800 & 0.85 & 0.35 & -0.014 \\
& & & & & & & & & & {(}-0.88) \\
\midrule
\multicolumn{11}{@{}l@{}}{\textit{Panel C: }} \\
\addlinespace
\multirow[t]{2}{=}{Average Age of the household respondent}
& 5000 & 44.7 & 12.8 & 3400 & 44.4 & 12.5 & 1016 & 44.9 & 13.1 & 0.511 \\
& & & & & & & & & & (0.87) \\
Percentage of Married
& 4000 & 0.86 & 0.35 & 345 & 0.87 & 0.34 & 800 & 0.85 & 0.35 & -0.014 \\
& & & & & & & & & & {(}-0.88) \\
\bottomrule
\multicolumn{11}{@{}l@{}}{\footnotesize \textit{t} statistics in parentheses}\\
\multicolumn{11}{@{}l@{}}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
\end{tabularx}
\end{table}
\end{document}