表格中的嵌套多列

表格中的嵌套多列

我正在尝试使用多列重新创建这样的嵌套表。

我想要实现的目标

我最好的猜测是以下,但它不起作用

% Table created by stargazer v.5.2.2 by Marek Hlavac
\begin{table}[!htbp] \centering 
  \caption{Ethnic Partitioning and Civil Conflict: Baseline Country Fixed Effects Estimates} 
  \label{} 
   \resizebox{0.9\columnwidth}{!}{%
\begin{tabular}{@{\extracolsep{5pt}}lcccccccc} 
%\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
\addlinespace
& \multicolumn{4}{c}{All ethnicity-country homelands} & \multicolumn{4}{c}{Ethnicity-country homelands close
to the national border} & \cmidrule(lr){2-5} \cmidrule(lr){6-9} \\
\multicolumn{3}{c}{All observations} & \multicolumn{1}{c}{Excl. Capitals} &  \multicolumn{3}{c}{All observations} & \multicolumn{1}{c}{Excl. Capitals} & \cmidrule(lr){2-5} \cmidrule(lr){6-9} \\
& \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)} & \multicolumn{1}{c}{(8)} \\ 
\hline \\[-1.8ex]
SPLIT (partitioning) & 0.0380 & 0.0480$^{*}$ & 0.0456 & 0.0321 & 0.0142 & $-$0.0132 & $-$0.0031 & $-$0.0203 \\ 
& (0.0268) & (0.0245) & (0.0298) & (0.0318) & (0.0407) & (0.0466) & (0.0441) & (0.0461) \\ 
& & & & & & & & \\ 
SPILL (adjacent split) & 0.0445 & 0.0910$^{**}$ & 0.0867$^{**}$ & 0.0787$^{*}$ & 0.0776 & 0.0834$^{*}$ & 0.1121$^{**}$ & 0.0958$^{*}$ \\ 
& (0.0498) & (0.0369) & (0.0395) & (0.0433) & (0.0575) & (0.0493) & (0.0485) & (0.0532) \\ 
& & & & & & & & \\ 
\hline \\[-1.8ex] 
Simple controls & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes \\ 
Location controls & No & No & Yes & Yes & No & Yes & Yes & Yes \\ 
Geographic controls & No & No & Yes & Yes & No & No & Yes & Yes \\ 
Country fixed Efffects & No & Yes & Yes & Yes & No & Yes & Yes & Yes \\ 
Observations & 1,238 & 1,238 & 1,238 & 1,156 & 619 & 619 & 619 & 572 \\ 
Adjusted R$^{2}$ & 0.2762 & 0.3733 & 0.3801 & 0.3767 & 0.2550 & 0.3747 & 0.3841 & 0.3838 \\ 
\hline 
\hline \\[-1.8ex] 
\multicolumn{9}{l}{Note....} \\ 
\end{tabular}}
\end{table} 

任何帮助将非常感激!

答案1

对我来说,您发布的屏幕截图看起来像是在tabularx允许单元格内自动换行的环境中创建的。

无论你做什么,我恳求你摆脱这种糟糕的\resizebox做法,或多或少担保表格将几乎无法阅读。相反,可以使用包sidewaystable提供的环境将表格置于横向模式rotating

在此处输入图片描述

\documentclass[a4paper,12pt]{article}
\usepackage{newtxtext,newtxmath} % optional: Times Roman text and math font
\usepackage{rotating} % for 'sidewaystable' env.
\usepackage{booktabs} % for well-spaced horizontal rules
\usepackage{tabularx} % for 'tabularx' env. and 'X' column type
\usepackage{ragged2e} % for '\Centering' macro
\renewcommand\tabularxcolumn[1]{b{#1}} % bottom-alignment of cell contents
\newcolumntype{Y}{>{\Centering}X}
\newcolumntype{Z}{>{\hsize=\dimexpr4\hsize+6\tabcolsep\relax}Y} % to span 4 'Y' columns

\begin{document}
\begin{sidewaystable} % switch to landscape mode
\caption{Ethnic partitioning and civil conflict: 
         Baseline country fixed effects estimates\strut} 
\label{tab:partitioning} 

\begin{tabularx}{\textwidth}{@{} l *{8}{Y} @{}} 
\toprule
& \multicolumn{4}{Z}{All ethnicity-country homelands} 
& \multicolumn{4}{Z@{}}{Ethnicity-country homelands close to the national border}\\ 
\cmidrule(lr){2-5} \cmidrule(l){6-9} 
& \multicolumn{3}{c}{All observations} & Excl. capitals 
& \multicolumn{3}{c}{All observations} & Excl. capitals \\ 
\cmidrule(lr){2-4} \cmidrule(lr){5-5} \cmidrule(lr){6-8} \cmidrule(l){9-9} 
& (1) & (2) & (3) & (4) & (5) & (6) & (7) & (8) \\ 
\midrule
\multicolumn{9}{@{}l}{\itshape Panel A\@. Negative binomial ML estimates}\\ 
\addlinespace
SPLIT (partitioning) & 0.0380 & 0.0480$^{*}$ & 0.0456 & 0.0321 & 0.0142 & $-$0.0132 & $-$0.0031 & $-$0.0203 \\ 
& (0.0268) & (0.0245) & (0.0298) & (0.0318) & (0.0407) & (0.0466) & (0.0441) & (0.0461) \\ 
\addlinespace
SPIL (adjacent split) & 0.0445 & 0.0910$^{**}$ & 0.0867$^{**}$ & 0.0787$^{*}$ & 0.0776 & 0.0834$^{*}$ & 0.1121$^{**}$ & 0.0958$^{*}$ \\ 
& (0.0498) & (0.0369) & (0.0395) & (0.0433) & (0.0575) & (0.0493) & (0.0485) & (0.0532) \\ 
\midrule
Simple controls & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes \\ 
Location controls & No & No & Yes & Yes & No & Yes & Yes & Yes \\ 
Geographic controls & No & No & Yes & Yes & No & No & Yes & Yes \\ 
Country fixed effects & No & Yes & Yes & Yes & No & Yes & Yes & Yes \\ 
Observations & 1,238 & 1,238 & 1,238 & 1,156 & 619 & 619 & 619 & 572 \\ 
Adjusted R$^{2}$ & 0.2762 & 0.3733 & 0.3801 & 0.3767 & 0.2550 & 0.3747 & 0.3841 & 0.3838 \\ 
\bottomrule
\end{tabularx}

\smallskip % no need to put the notes inside the tabularx env.
Notes: \dots
\end{sidewaystable} 
\end{document}

相关内容