1

I have the two following LaTeX files: formelshare-lev-cov_cleaned_data.tex:

\begin{table}[H]\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{Original Data}
\begin{tabular}{l*{3}{c}}
\hline\hline
                    &\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}\\
                    &\multicolumn{1}{c}{Formal share}&\multicolumn{1}{c}{Formal share}&\multicolumn{1}{c}{Formal share}\\
\hline
Protection          &        0.03         &        0.05\sym{+}  &        0.00         \\
                    &      (0.02)         &      (0.02)         &      (0.02)         \\
[1em]
Tax consulting      &       -0.00         &       -0.01         &       -0.02         \\
                    &      (0.02)         &      (0.02)         &      (0.02)         \\
\hline
Observations        &        4199         &        2576         &        1623         \\
\(R^{2}\)           &       0.466         &       0.458         &       0.513         \\
ControlMean         &        0.35         &        0.38         &        0.32         \\
Covariates          &         Yes         &         Yes         &         Yes         \\
Sample              &        Full         &         Pre         &        Post         \\
\hline\hline
\multicolumn{4}{l}{\footnotesize Standard errors in parentheses}\\
\multicolumn{4}{l}{\footnotesize \sym{+} \(p<0.10\), \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
\end{tabular}
\end{table}

and formelshare-lev-cov_cleaned_data_new.tex:

\begin{table}[H]\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{New Data, excluding outliers}
\begin{tabular}{l*{3}{c}}
\hline\hline
                    &\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}\\
                    &\multicolumn{1}{c}{Formal share}&\multicolumn{1}{c}{Formal share}&\multicolumn{1}{c}{Formal share}\\
\hline
Protection          &        0.02         &        0.03         &       -0.01         \\
                    &      (0.03)         &      (0.03)         &      (0.02)         \\
[1em]
Tax consulting      &        0.01         &        0.01         &       -0.01         \\
                    &      (0.03)         &      (0.03)         &      (0.03)         \\
\hline
Observations        &        4199         &        2576         &        1623         \\
\(R^{2}\)           &       0.399         &       0.396         &       0.445         \\
ControlMean         &        0.29         &        0.30         &        0.27         \\
Covariates          &         Yes         &         Yes         &         Yes         \\
Sample              &        Full         &         Pre         &        Post         \\
\hline\hline
\multicolumn{4}{l}{\footnotesize Standard errors in parentheses}\\
\multicolumn{4}{l}{\footnotesize \sym{+} \(p<0.10\), \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
\end{tabular}
\end{table}

and would like to put them side-by-side. I have attempted to use the following code:

\begin{figure}[h!]
\begin{minipage}[b]{0.4\linewidth}
\input{tabs-figs-2017-02/formelshare-lev-cov_cleaned_data.tex}
\end{minipage}
\begin{minipage}[b]{0.4\linewidth}
\input{tabs-figs-2017-02/formelshare-lev-cov_cleaned_data_new.tex}
\end{minipage}
\end{figure}

However, some of the columns are on top of each other, probably due to the width of the individual tables. I was wondering if:

1) The tables could be resized using the above code? When attempting, I would then get the tables on top of each other as opposed to side-by-side;

2) If there is a code to also merge the two tables, as they have the same first column in common.

  • 1
    just put \footnotesize after \begin{figure} or whatever size is needed, also remove the table environments from the input files (you can't nest table) als, unrelated don't use [h!] latex usually warns you about that and changes it to [ht] but [htp] is far less likely to take the table to the end of the document. – David Carlisle Jun 18 '18 at 20:49
  • Welcome to TeX.Stackexchange! – user36296 Jun 18 '18 at 20:49
2

Unless your textblock is unusually wide, you need to make the tabular environments less wide. This, in turn, can be done by splitting the header text "Formal share" across two lines.

Instead of writing \hline\hline, do familiarize yourself with the booktabs package and its user macros \toprule, \midrule, \cmidrule, \bottomrule, and \addlinespace.

enter image description here

\RequirePackage{filecontents}

\begin{filecontents}{formelshare-lev-cov_cleaned_data.tex}
\centering
\caption{Original Data}
\begin{tabular}{@{}l*{3}{c}@{}}
\toprule
&(1) & (2) & (3)\\
&Formal & Formal & Formal \\
&share & share & share \\
\midrule
Protection      &     0.03     &  0.05\sym{+} &    0.00        \\
                &   (0.02)     &   (0.02)     &   (0.02)       \\
\addlinespace
Tax consulting  &    $-$0.00   &   $-$0.01    &    $-$0.02     \\
                &   (0.02)     &   (0.02)     &   (0.02)       \\
\addlinespace
Observations    &     4199     &     2576     &     1623       \\
\(R^{2}\)       &    0.466     &    0.458     &    0.513       \\
ControlMean     &     0.35     &     0.38     &     0.32       \\
Covariates      &      Yes     &      Yes     &      Yes       \\
Sample          &     Full     &      Pre     &     Post       \\
\midrule[\heavyrulewidth]
\multicolumn{4}{@{}l}{\footnotesize Standard errors in parentheses}\\
\multicolumn{4}{@{}l}{\footnotesize \sym{+} \(p<0.10\), \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
\end{tabular}
\end{filecontents}

\begin{filecontents}{formelshare-lev-cov_cleaned_data_new.tex}
\centering
\caption{New Data, excluding outliers}
\begin{tabular}{@{}l*{3}{c}@{}}
\toprule
&(1) & (2) & (3)\\
&Formal & Formal & Formal \\
&share & share & share \\
\midrule
Protection      &     0.02     &     0.03     &    $-$0.01   \\
                &   (0.03)     &   (0.03)     &   (0.02)     \\
\addlinespace
Tax consulting  &     0.01     &     0.01     &    $-$0.01   \\
                &   (0.03)     &   (0.03)     &   (0.03)     \\
\addlinespace
Observations    &     4199     &     2576     &     1623     \\
\(R^{2}\)       &    0.399     &    0.396     &    0.445     \\
ControlMean     &     0.29     &     0.30     &     0.27     \\
Covariates      &      Yes     &      Yes     &      Yes     \\
Sample          &     Full     &      Pre     &     Post     \\
\midrule[\heavyrulewidth]
\multicolumn{4}{@{}l}{\footnotesize Standard errors in parentheses}\\
\multicolumn{4}{@{}l}{\footnotesize \sym{+} \(p<0.10\), \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}
\end{tabular}
\end{filecontents}

\documentclass{article}
\usepackage{amsmath,booktabs,caption}
\captionsetup{skip=0.333\baselineskip}
\usepackage[margin=2.5cm]{geometry} % set page parameters suitably
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}

\begin{document}
\begin{table}[h!]
\begin{minipage}[t]{0.5\textwidth}
  \input formelshare-lev-cov_cleaned_data
\end{minipage}% <-- this "%" symbol is important
\begin{minipage}[t]{0.5\textwidth}
  \input formelshare-lev-cov_cleaned_data_new
\end{minipage}
\end{table}
\end{document}
1

I propose this code, based on floatrow, the S column type from siunitx for the alignment of numbers threeparttable for table notes and booktabs for a more professional look of rules in tables:

\documentclass[a4paper]{article}
\usepackage[showframe]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{caption, booktabs}
\usepackage{floatrow}
\usepackage{threeparttable} 
\usepackage{siunitx}

\def\sym#1{\ensuremath{{}^{#1}}}

\begin{document}

\begin{table}[H]
\centering
\floatsetup{style=plain, capposition=below, floatrowsep=qquad}
\sisetup{table-format=1.3, table-number-alignment=center, table-space-text-pre=(, table-align-text-pre=false, table-space-text-post=), table-align-text-post=false}
\begin{floatrow}
\ttabbox{\caption{Original Data}}{%
\begin{threeparttable}
\begin{tabular}{l*{3}{S}@{}}
\toprule\midrule
 & \multicolumn{3}{c@{}}{Formal share} \\
 \cmidrule(lr){2-4}
 &{(1)} & {(2)} &{ (3)} \\
\midrule
Protection & 0.03 & 0.05\sym{+} & 0.00 \\
 & {(}0.02{)} & {(}0.02{)} &{(}0.02{)} \\
[1em]
Tax consulting & -0.00 & -0.01 & -0.02 \\
 & {(}0.02{)} & {(}0.02{)} &{(}0.02{)} \\
\midrule
Observations & {4199} & {2576} & {1623} \\
\(R^{2}\) & 0.466 & 0.458 & 0.513 \\
ControlMean & 0.35 & 0.38 & 0.32 \\
Covariates & {Yes} & {Yes} & {Yes} \\
Sample & {Full} & {Pre} & {Post} \\
\midrule\bottomrule
\end{tabular}\footnotesize
\begin{tablenotes}[para]
\item[]Standard errors in parentheses
\item[+]\sym{+} \(p<0.10\), \item[*] \(p<0.05\), \item[**] \(p<0.01\), \item[***] \(p<0.001\)
\end{tablenotes}
\end{threeparttable}}
%
\ttabbox{\caption{New Data, excluding outliers}}%
{\begin{threeparttable}
\begin{tabular}{l*{3}{S}@{}}
\toprule\midrule
 & \multicolumn{3}{c@{}}{Formal share} \\
 \cmidrule(lr){2-4}
                    &{(1)} & {(2)} & {(3)} \\
\midrule
Protection & 0.02 & 0.03 & -0.01 \\
                    & {(}0.03{)} & {(}0.03{)} & {(}0.02{)} \\
[1em]
Tax consulting & 0.01& 0.01 & -0.01 \\
                    & {(}0.03{)} & {(}0.03{)} & {(}0.03{)} \\
\midrule
Observations & {4199} & {2576} & {1623} \\
\(R^{2}\) & 0.399 & 0.396 & 0.445 \\
ControlMean & 0.29 & 0.30 & 0.27\\
Covariates & {Yes} & {Yes} & {Yes} \\
Sample & {Full} & {Pre} & {Post} \\
\midrule\bottomrule
\end{tabular}\footnotesize
\begin{tablenotes}[para]
\item[]Standard errors in parentheses
\item[+]\sym{+} \(p<0.10\), \item[*] \(p<0.05\), \item[**] \(p<0.01\), \item[***] \(p<0.001\)
\end{tablenotes}
\end{threeparttable}}
\end{floatrow}
\end{table}

\end{document} 

enter image description here

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.