4

Somehow \toprule does not underline the whole row of my table. Hopefully, someone can explain to me what I am doing wrong. My ultimate goal is to create a table similar to:Snippit of ANDREY GOLUBOV, DIMITRIS PETMEZAS, and NICKOLAOS G. TRAVLOS paper, When It Pays to Pay Your Investment Banker, 2012

Copy of my shortened code:

\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}

Good to mention is that the code is created using the STATA package esstab + booktabs.

3
  • \textwidth on a landscape page eould equal the width of a line of text in a portrait page. To get the width of a line of text in a landscape page, you can use \linewidth instead. Apart from that, a tabularx at least needs one X type column. I don't see any X type columns in your code, so don't use tabularx.
    – leandriis
    Mar 29, 2020 at 14:19
  • 1
    @leandriis thanks! Changed to \linewidth solved it. Indeed, the X is missing. Thanks for the catch and comments.
    – Oliver
    Mar 29, 2020 at 14:26
  • I have edited the title of your question since the commands from booktabs are called ...rule instead of ...line.
    – leandriis
    Mar 29, 2020 at 14:45

3 Answers 3

4

I understand that the table is automatically generated, but after that you need to fix it so it's readable and syntactically sound. For instance, tabularx here is completely useless, because no X column is specified.

Here's a reworking using siunitx and some tricks to reduce the header widths.

\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}

enter image description here

2
  • +1. I think it would be a good idea (not implemented by the OP, but good nevertheless...) to replace the final header, (2-3), with $(2)-(3)$ or, better yet, $(3)-(2)$, as the numbers in the b column are merely the differences of the numbers in the two preceding mean columns.
    – Mico
    Mar 29, 2020 at 15:39
  • @Mico Suggestion implemented
    – egreg
    Mar 29, 2020 at 16:18
3

In the following example, I have removed the tabularx and in order to make the table fit into the page, I have introduced linebreaks in the headers. I have also added the \cmidrules and removed the unnecessary columns (in the original you declared a total of 17 columns but only used 9). In the second table I have added siunitx to improve the alignment of the numbers in the table.

enter image description here

\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}
1

Here's a solution that continues the use of a tabularx environment.

I've reduced the total number of columns to 9 and have assigned a centered version of the X column type to all 8 data columns. I've also used several \cmidrule directives to provide more visual structure to the header material. Observe that by allowing line breaks in the header cells, it becomes much easier to fit the entire table in landscape format.

enter image description here

\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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .