4

I am trying to build a table with multiple panels, for instance:

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{tabularx}
\usepackage{booktabs}
\newcolumntype{Y}{>{\raggedleft\arraybackslash}X}% raggedleft column X
\begin{document}

   \begin{table}[htb]
    \caption{Descriptive Statistics and Correlations for Variables}
    \label{tbl:stats-and-correlations}


    \begin{tabularx}{\linewidth}{l*{9}{Y}}
        \toprule
            \multicolumn{7}{l}{\textbf{Panel A}} \\

    Statistic & \multicolumn{1}{c}{N} & \multicolumn{1}{c}{Mean} & \multicolumn{1}{c}{S.D.} & \multicolumn{1}{c}{Min} & \multicolumn{1}{c}{Pctl(25)} & \multicolumn{1}{c}{Median} & \multicolumn{1}{c}{Pctl(75)} & \multicolumn{1}{c}{Max} \\ 
    \hline \\[-1.8ex] 
    net profit & 595 & 309,923.500 & 1,235,088.000 & 15 & 20,324.5 & 64,431 & 226,601.5 & 17,095,868 \\ 
    total assets & 623 & 37,255,614.000 & 140,879,480.000 & 42,077 & 1,560,427 & 4,326,558 & 16,847,227 & 1,803,048,120 \\ 
    RoA & 595 & 0.017 & 0.014 & 0.0001 & 0.008 & 0.014 & 0.022 & 0.108 \\ 
    number of board members & 544 & - & - & 1 & 10 & 12 & 15 & 39 \\ 
    total staff number  & 542 & - & - & 5 & 26 & 50 & 160 & 3,505 \\ 
    no of branch covered cities & 551 & - & - & 1 & 1 & 2 & 5 & 156 \\ 
    establish year & 493 & - & - & 1,907 & 1,919 & 1,925 & 1,930 & 1,934 \\ 
    bank age & 493 & - & - & 1 & 4 & 8 & 15 & 29 \\  
    \end{tabularx}

    \begin{tabularx}{\linewidth}{l*{7}{Y}}
        \toprule
        \multicolumn{7}{l}{\textbf{Panel B: Correlations}} \\
        \midrule
        & Var.\ 1 & Var.\ 2 & Var.\ 3 & Var.\ 4 & Var.\ 5 & Var.\ 6 & Var.\ 7 \\
        Variable~1 &    0.78 &    0.37 &    0.48 &    0.10 &    0.13 &    0.58 &    0.41 \\
        Variable~2 &    0.46 &    0.86 &    0.96 &    0.44 &    0.15 &    0.56 &    0.31 \\
        Variable~3 &    0.03 &    0.75 &    0.11 &    0.44 &    0.71 &    0.06 &    0.26 \\
        Variable~4 &    0.21 &    0.25 &    0.38 &    0.88 &    0.24 &    0.52 &    0.46 \\
        Variable~5 &    0.20 &    0.93 &    0.54 &    0.96 &    0.55 &    0.82 &    0.62 \\
        Variable~6 &    0.67 &    0.85 &    0.74 &    0.99 &    0.27 &    0.48 &    0.85 \\
        Variable~7 &    0.82 &    0.89 &    0.68 &    0.06 &    0.02 &    0.30 &    0.10 \\
        \bottomrule


    \end{tabularx}

   {\footnotesize   [1]\ Footnote 1: Variable~1 is calculated as\ldots \endgraf
    [2]\ Correlations are Pearson. vxccccccccccccccccccccccccccccccccccCCCdasdasjkdkjasdkadsdsajdnsjakdjlkasld}
   \end{table}

      \end{document}

the result:

enter image description here

Any idea about the overlapping?

  • 1
    The solution here is to make the columns of a different specification, like r, not Y (for those where the overlapping occur). – Werner Sep 29 '16 at 5:21
  • @Werner - See my answer for an implementation of your recommendation. :-) – Mico Sep 29 '16 at 5:28
6

The upper table has two issues:

  • The numbers in the first two rows are of entirely different magnitudes from those in the remaining rows.

  • Even if you rescale the numbers -- below, I suggest factors of 10^3 and 10^6 -- the table still won't fit because the data rows are all made to occupy the same widths. Given the overall space limit, this results in more than enough space for some columns but not enough space for others.

The remedy is to (a) rescale the numbers in the first two data rows and (b) use a tabular* environment instead of a tabularx environment. (A chief reason for using tabularx is when you need to let overly long lines wrap automatically. This is not the case here. Actually, it would be a really bad idea to let long numbers wrap automatically!) The overall width will still be \linewidth, but the fitting is achieved by letting the column widths vary as needed. For symmetry, I suggest you use a tabular* environment for the lower table as well.

Incidentally, I don't think one should use commas as thousands-separators for four-digit year numbers.

enter image description here

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{booktabs}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro
\begin{document}

\begin{table}[htb]
\setlength\tabcolsep{0pt} % let LaTeX figure out optimal widths
\caption{Descriptive Statistics and Correlations for Variables}
\label{tbl:stats-and-correlations}

\begin{tabular*}{\linewidth}{l@{\extracolsep{\fill}}c*{7}{r}}
\toprule
\multicolumn{8}{l}{\textbf{Panel A: Descriptive Statistics}} \\

& N & \mc{Mean} & \mc{S.D.} & \mc{Min} & \mc{Pctl(25)} & \mc{Median} & \mc{Pctl(75)} & \mc{Max} \\ 
\midrule
net profit ($\times10^3$)& 595 & 309.92 & 1,235.09 & 0.0015 & 20.32 & 64.43 & 226.60 & 17,095.87 \\ 
total assets ($\times10^6$) & 623 & 37,255.6 & 140,879.5 & 0.042 & 1,560.4 & 4,326.6 & 16,847.2 & 1,803,048.1 \\ 
    RoA & 595 & 0.017 & 0.014 & 0.0001 & 0.008 & 0.014 & 0.022 & 0.108 \\ 
    number of board members & 544 & - & - & 1 & 10 & 12 & 15 & 39 \\ 
    total staff number  & 542 & - & - & 5 & 26 & 50 & 160 & 3,505 \\ 
    no of branch covered cities & 551 & - & - & 1 & 1 & 2 & 5 & 156 \\ 
    establish year & 493 & - & - & 1907 & 1919 & 1925 & 1930 & 1934 \\ 
    bank age & 493 & - & - & 1 & 4 & 8 & 15 & 29 \\  
\bottomrule
\end{tabular*}

\begin{tabular*}{\linewidth}{l@{\extracolsep{\fill}}*{7}{r}}
\addlinespace
\multicolumn{7}{l}{\textbf{Panel B: Correlations}} \\
\midrule
& Var.\ 1 & Var.\ 2 & Var.\ 3 & Var.\ 4 & Var.\ 5 & Var.\ 6 & Var.\ 7 \\
Variable~1 &    0.78 &    0.37 &    0.48 &    0.10 &    0.13 &    0.58 &    0.41 \\
Variable~2 &    0.46 &    0.86 &    0.96 &    0.44 &    0.15 &    0.56 &    0.31 \\
Variable~3 &    0.03 &    0.75 &    0.11 &    0.44 &    0.71 &    0.06 &    0.26 \\
Variable~4 &    0.21 &    0.25 &    0.38 &    0.88 &    0.24 &    0.52 &    0.46 \\
Variable~5 &    0.20 &    0.93 &    0.54 &    0.96 &    0.55 &    0.82 &    0.62 \\
Variable~6 &    0.67 &    0.85 &    0.74 &    0.99 &    0.27 &    0.48 &    0.85 \\
Variable~7 &    0.82 &    0.89 &    0.68 &    0.06 &    0.02 &    0.30 &    0.10 \\
\bottomrule
\addlinespace
\end{tabular*}
\footnotesize   
[1]\ Footnote 1: Variable~1 is calculated as\ldots \endgraf
    [2]\ Correlations are Pearson. vxccccccccccccccccccccccccccccccccccCCCdasdasjkdkjasdkadsdsajdnsjakdjlkasld
\end{table}
\end{document}
  • 2
    @EnricoMariaDeAngelis - Thanks! Writing (in thousands) and (in millions) instead of ($\times10^3$) and ($\times10^6$) might, at the margin, reduce some ambiguity regarding the scaling. Actually, if this were my table, I'd almost certainly re-organize the way the material is presented, so as not to have to show assets (in billions of currency units), bank age (less than 100, in years), and Return on Assets (a fractional term between 0 and 1) in such close proximity. – Mico Sep 29 '16 at 6:41
  • 2
    +1 for not using tabularx for data tables:-) – David Carlisle Sep 29 '16 at 6:44
  • 1
    @EnricoMariaDeAngelis - I'll offer my own argument against tabularx. (Let's see if David disagrees...) A principal reason for using tabularx is to let LaTeX perform automatic line wrapping on material that is (in some sense or other) "too wide" in one or more columns. For the table at hand, though, line wrapping would be catastrophic. Since line wrapping is out of the question, it's better to use a tabular* environment if the objective is still to make the table to take up the full width of the textblock. That, or just a plain, centered tabular environment... – Mico Sep 29 '16 at 8:13
  • 1
    @EnricoMariaDeAngelis not sure what reference you need, I wrote tabularx and I'd never use it for such a table:-) tabularx is all about adjusting the final table width by altering the line breaking within columns of text. In a numeric table where there is no line breaking in the cells tabularx can only do harm, tabular* is better, and usually tabular is better still (stretching the table to full width just makes it harder to read) not so bad here as it is almost full width anyway so it just removes the margins but for smaller tables it does not improve the table – David Carlisle Sep 29 '16 at 8:15
  • 1
    @Mico groupthink wins the day :-) – David Carlisle Sep 29 '16 at 8:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.