Tabularx、landscape、\toprule \midrule 不完全划出行下划线

Tabularx、landscape、\toprule \midrule 不完全划出行下划线

不知何故\toprule没有给我的表格的整行加下划线。希望有人能向我解释我做错了什么。我的最终目标是创建一个类似于以下内容的表格:ANDREY GOLUBOV、DIMITRIS PETMEZAS 和 NICKOLAOS G. TRAVLOS 论文《何时向投资银行家支付报酬》的摘录,2012 年

我的缩短代码的副本:

\documentclass[12pt,twoside]{article}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{lscape}
        \begin{landscape}
    {
    \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
    \begin{tabularx}{\textwidth}{l*{4}{lccc}}
    \toprule
                        &\multicolumn{2}{c}{Full sample (1)}  &\multicolumn{2}{c}{Top 50\% experience target ind. (2)}  &\multicolumn{2}{c}{Bottem 50\% Experience target ind(3)}  &\multicolumn{2}{c}{(2-3)}           \\
                        &\multicolumn{2}{c}{}     &\multicolumn{2}{c}{}     &\multicolumn{2}{c}{}     &\multicolumn{2}{c}{}              \\
                        &        mean&          sd&        mean&          sd&        mean&          sd&           b         &           t\\
    \midrule
    Book to Market       &       2.911&      18.792&       3.341&      16.830&       2.642&      19.949&      -0.699         &    (-0.371)\\
    Free cash flow      &     225.883&    4275.873&     325.020&    6726.092&     163.922&    1242.414&    -161.098         &    (-0.290)\\
    Leverage            &       0.578&       0.204&       0.601&       0.206&       0.564&       0.202&      -0.037         &    (-1.734)\\
    Relative size       &      87.852&     667.603&      50.216&     184.712&     111.334&     838.031&      61.119         &     (1.075)\\
    \midrule
    Observations        &         390&            &         150&            &         240&            &         390         &            \\
    \bottomrule
    \end{tabularx}
    }
    \end{landscape}

值得一提的是,该代码是使用 STATA 包 esstab + booktabs 创建的。

答案1

我知道表格是自动生成的,但之后你需要修复它,使其可读且语法合理。例如,tabularx这里完全没用,因为没有X指定列。

这里重新使用了siunitx一些技巧来减少标题宽度。

\documentclass[12pt,twoside]{article}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{rotating}

\newcommand{\splitcell}[2][c]{\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}

\begin{document}

\begin{sidewaystable}
\centering

\sisetup{% we don't need to parse uncertainty
  input-open-uncertainty={},
  input-close-uncertainty={}
}

\caption{Some caption to the table}

\begin{tabular}{
  @{}
  l
  S[table-format=3.3]
  S[table-format=4.3]
  S[table-format=3.3]
  S[table-format=4.3]
  S[table-format=3.3]
  S[table-format=4.3]
  S[table-format=-3.3]
  S[table-format=-1.3,
    table-space-text-pre={(},
    table-space-text-post={)},
    table-align-text-pre=false
  ]
  @{}
}
\toprule
& \multicolumn{2}{c}{Full sample (1)}
& \multicolumn{2}{c}{\splitcell[t]{Top 50\% \\ experience \\ target ind. (2)}}
& \multicolumn{2}{c}{\splitcell[t]{Bottom 50\% \\ experience \\ target ind. (3)}}
& \multicolumn{2}{c}{$(3)-(2)$}
\\
\cmidrule(lr){2-3}\cmidrule(lr){4-5}\cmidrule(lr){6-7}\cmidrule(l){8-9}
& {mean} & {sd} & {mean} & {sd} & {mean} & {sd} & {b} & {t} \\
\midrule
Book to Market &   2.911 &   18.792 &   3.341 &   16.830 &   2.642 &   19.949 &   -0.699 & (-0.371)\\
Free cash flow & 225.883 & 4275.873 & 325.020 & 6726.092 & 163.922 & 1242.414 & -161.098 & (-0.290)\\
Leverage       &   0.578 &    0.204 &   0.601 &    0.206 &   0.564 &    0.202 &   -0.037 & (-1.734)\\
Relative size  &  87.852 &  667.603 &  50.216 &  184.712 & 111.334 &  838.031 &   61.119 &  (1.075)\\
\midrule
Observations   &  {390}  &          &   {150} &          &  {240}  &          &    {390} &         \\
\bottomrule
\end{tabular}

\end{sidewaystable}

\end{document}

在此处输入图片描述

答案2

在以下示例中,我删除了 和 ,tabularx以便使表格适合页面,我在标题中引入了换行符。我还添加了 s\cmidrule并删除了不必要的列(在原始示例中,您总共声明了 17 列,但只使用了 9 列)。在第二个表格中,我添加了siunitx以改善表格中数字的对齐方式。

在此处输入图片描述

\documentclass{article}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{pdflscape}
\usepackage{makecell}
\usepackage{siunitx}
\begin{document}

\begin{landscape}
\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{tabular}{l*{2}{lccc}}
\toprule
                    &\multicolumn{2}{c}{Full sample (1)}  &\multicolumn{2}{c}{\makecell{Top 50\%\\ experience target \\ind. (2)}}  &\multicolumn{2}{c}{\makecell{Bottom 50\%\\ Experience target\\ ind(3)}}  &\multicolumn{2}{c}{(2-3)}           \\
          \cmidrule(r){2-3} \cmidrule(lr){4-5} \cmidrule(lr){6-7} \cmidrule(l){8-9}
                    &        mean&          sd&        mean&          sd&        mean&          sd&           b         &           t\\
\midrule
Book to Market       &       2.911&      18.792&       3.341&      16.830&       2.642&      19.949&      -0.699         &    (-0.371)\\
Free cash flow      &     225.883&    4275.873&     325.020&    6726.092&     163.922&    1242.414&    -161.098         &    (-0.290)\\
Leverage            &       0.578&       0.204&       0.601&       0.206&       0.564&       0.202&      -0.037         &    (-1.734)\\
Relative size       &      87.852&     667.603&      50.216&     184.712&     111.334&     838.031&      61.119         &     (1.075)\\
\midrule
Observations        &         390&            &         150&            &         240&            &         390         &            \\
\bottomrule
\end{tabular}

\bigskip

\begin{tabular}{l
                *{3}{
                S[table-format=3.3]
                S[table-format=4.3]}
                S[table-format=-3.3]
                S[table-format=-1.3,
                  input-open-uncertainty= ,
                  input-close-uncertainty  = ,
                  table-space-text-pre={(}, 
                  table-space-text-post={)},
                  table-align-text-pre = false]
           }
\toprule
     &\multicolumn{2}{c}{Full sample (1)}  
         &\multicolumn{2}{c}{\makecell{Top 50\%\\ experience target \\ind. (2)}}  
             &\multicolumn{2}{c}{\makecell{Bottom 50\%\\ Experience target\\ ind(3)}}  
                 &\multicolumn{2}{c}{(2-3)}           \\
          \cmidrule(r){2-3} \cmidrule(lr){4-5} \cmidrule(lr){6-7} \cmidrule(l){8-9}
    &        {mean}&          {sd}
        &        {mean}&          {sd}
            &        {mean}&          {sd}
                &           {b}         &           {t}\\
\midrule
Book to Market       &       2.911&      18.792&       3.341&      16.830&       2.642&      19.949&      -0.699         &    (-0.371)\\
Free cash flow      &     225.883&    4275.873&     325.020&    6726.092&     163.922&    1242.414&    -161.098         &    (-0.290)\\
Leverage            &       0.578&       0.204&       0.601&       0.206&       0.564&       0.202&      -0.037         &    (-1.734)\\
Relative size       &      87.852&     667.603&      50.216&     184.712&     111.334&     838.031&      61.119         &     (1.075)\\
\midrule
Observations        &         {390}&            &         {150}&            &         {240}&            &         {390}         &            \\
\bottomrule
\end{tabular}
\end{landscape}
\end{document}

答案3

这是一个继续使用tabularx环境的解决方案。

我已将总列数减少到,并为所有 8 个数据列9分配了居中版本的列类型。我还使用了几个指令来为标题材料提供更多视觉结构。请注意,通过允许标题单元格中的换行符,可以更轻松地将整个表格调整为横向格式。X\cmidrule

在此处输入图片描述

\documentclass[12pt,twoside]{article}
\usepackage[a4paper,margin=2.5cm]{geometry} % set suitable page parameters
\usepackage{booktabs,tabularx,ragged2e}
\newcolumntype{C}{>{\Centering\arraybackslash}X}
\newcommand\doublehsize{\hsize=\dimexpr2\hsize+2\tabcolsep\relax} % handy shortcut macro
\usepackage{rotating}

\begin{document}

\begin{sidewaystable}
\begin{tabularx}{\textwidth}{@{} l *{8}{C} @{}}
\toprule
&\multicolumn{2}{>{\doublehsize}C}{Full sample (1)}  
&\multicolumn{2}{>{\doublehsize}C}{Top 50\% experience target ind.~(2)}  
&\multicolumn{2}{>{\doublehsize}C}{Bottom 50\% experience target ind.~(3)}  
&\multicolumn{2}{>{\doublehsize}C}{$(2)-(3)$} \\

\cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(lr){6-7} \cmidrule(l){8-9}
 & mean & sd & mean & sd & mean & sd & b & t\\
\midrule
Book to Market  &   2.911&   18.792&   3.341&   16.830&   2.642&   19.949&   $-0.699$ & ($-0.371$)\\
Free cash flow  & 225.883& 4275.873& 325.020& 6726.092& 163.922& 1242.414& $-161.098$ & ($-0.290$)\\
Leverage        &   0.578&    0.204&   0.601&    0.206&   0.564&    0.202&   $-0.037$ & ($-1.734$)\\
Relative size   &  87.852&  667.603&  50.216&  184.712& 111.334&  838.031&   $61.119$ &  ($1.075$)\\
\midrule
Observations    &  390 &  &  150 &  &  240 &  &  390      & \\
\bottomrule
\end{tabularx}
\end{sidewaystable}
\end{document}

相关内容