4

I have been trying to reduce the space between the columns in a table that was exported directly from Stata.

The table is the following:

\begin{table}[H]
\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{Regression\label{tab1}}
\begin{tabular*}{1.1\hsize}{@{\hskip\tabcolsep\extracolsep\fill}l*{4}{D{.}{.}{-1}}}
\toprule

I know I need to work with \tabcolsep but I am not sure how to isolate it from that big piece of code I have already.


Following @leandriis feedback I replaced 1.1\hsize with \textwidth, but that does not seem to work: what I had: My output before

I want the columns to be closer together, as that way it is out of the margins of the rest of my work.

And if I include \textwidththis is what I get: My output with textwidth


My minimal working example as requested:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pdflscape}
\usepackage{graphicx}
\usepackage{indentfirst}
\usepackage{geometry}
\usepackage{dcolumn}
\usepackage{wrapfig}
\usepackage{booktabs}
\usepackage{placeins}
\usepackage{float}
\restylefloat{table}
\graphicspath{ {./mypath/} }
\begin{document}
\setlength{\parindent}{3em}
\setlength{\parskip}{1em}


\FloatBarrier
\begin{small}
     \input{\begin{table}[H]\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{Regression with country and year dummies\label{tab1}}
\begin{tabular*}{1.1\hsize}{@{\hskip\tabcolsep\extracolsep\fill}l*{4}{D{.}{.}{-1}}}
\toprule
                    &\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}&\multicolumn{1}{c}{(4)}\\
                    &\multicolumn{1}{c}{Group 1}&\multicolumn{1}{c}{Group 2}&\multicolumn{1}{c}{Group 3}&\multicolumn{1}{c}{Group 4}\\
\midrule
propyes1            &       305.1\sym{***}&                     &                     &                     \\
                    &    (205.46)         &                     &                     &                     \\
\addlinespace
gdppc               &  -0.0000193\sym{***}&  0.00000260\sym{*}  &  -0.0000174\sym{***}&  -0.0000147\sym{***}\\
                    &    (-18.19)         &      (2.38)         &    (-16.38)         &    (-13.72)         \\
\addlinespace
propyes2            &                     &       17.19\sym{***}&                     &                     \\
                    &                     &     (75.74)         &                     &                     \\
\addlinespace
propyes3            &                     &                     &       9.964\sym{***}&                     \\
                    &                     &                     &     (40.51)         &                     \\
\addlinespace
propyes4            &                     &                     &                     &      -6.050\sym{***}\\
                    &                     &                     &                     &    (-35.42)         \\
\addlinespace
Constant            &       13.66\sym{***}&       58.99\sym{***}&       60.07\sym{***}&       64.76\sym{***}\\
                    &     (84.14)         &    (541.52)         &    (478.00)         &    (667.77)         \\
\midrule
Observations        &      386364         &      386364         &      386364         &      386364         \\
\bottomrule
\multicolumn{5}{l}{\footnotesize \textit{t} statistics in parentheses}\\
\multicolumn{5}{l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
\end{tabular*}
\end{table}}

\end{small}
 \FloatBarrier

\end{document}

17
  • You can add, say just after \begin{table}, \setlength{\tabcolsep}{3pt} (the default is 6pt).
    – Bernard
    Dec 20, 2020 at 11:32
  • Welcome to TeX.SX! What exactly should your output look like? Do you want a table that is as wide as the textwidth? If so, replace 1.1\hsizewith \textwidth. With this adjustment, your table fits onto the page and at the same time, the distance between the columns is reduced. If you want your table to be as wide as it naturally is, you could give \begin{tabular}{l*{4}{D{.}{.}{-1}}} a try.
    – leandriis
    Dec 20, 2020 at 11:34
  • @Bernard: Since the code uses tabular*in combination with \extracolsep, explicitly reducing the value of \tabcolsep won't make much of a difference here.
    – leandriis
    Dec 20, 2020 at 11:38
  • @Bernard Hello, and thank you for your quick reply! I have tried adding that, but should I then remove the \tabcolstep that appears in the middle of my code just like that? Because if I add it without touching anything else everything remains intact
    – pfragon
    Dec 20, 2020 at 11:40
  • the only reason to have \begin{tabular*}{1.1\hsize} is to force the column spacing to be larger than normal (and force the table to be wider than the page) Dec 20, 2020 at 11:41

2 Answers 2

4

Here is my suggestion beased on siunitx. (Red lines indicate page margins, Numbers are aligned with respect to the decimal separator, number of observations are horizontally centered within the corresponding columns.

enter image description here

\documentclass{article}

\usepackage{siunitx}
\usepackage{booktabs}

\usepackage{geometry}

\begin{document}

\begin{table}
\small
\setlength{\tabcolsep}{3pt}
\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{Regression\label{tab1}}
\begin{tabular}{@{}l*{4}{S[table-format=-3.8,
                           input-symbols = {()},
                           table-space-text-pre=), 
                           table-space-text-post=\sym{***}, 
                           table-align-text-post=false, 
                           table-align-text-pre=false ]}@{}}
\toprule
                    &{(1)}&{(2)}&{(3)}&{(4)}\\
                    &{Group 1}&{Group 2}&{Group 3}&{Group 4}\\
\midrule
propyes1            &       305.1\sym{***}&                     &                     &                     \\
                    &    (205.46)         &                     &                     &                     \\
\addlinespace
gdppc               &  -0.0000193\sym{***}&  0.00000260\sym{*}  &  -0.0000174\sym{***}&  -0.0000147\sym{***}\\
                    &    {(}-18.19)         &      (2.38)         &    {(}-16.38)         &    {(}-13.72)         \\
\addlinespace
propyes2            &                     &       17.19\sym{***}&                     &                     \\
                    &                     &     (75.74)         &                     &                     \\
\addlinespace
propyes3            &                     &                     &       9.964\sym{***}&                     \\
                    &                     &                     &     (40.51)         &                     \\
\addlinespace
propyes4            &                     &                     &                     &      -6.050\sym{***}\\
                    &                     &                     &                     &    {(}-35.42)         \\
\addlinespace
Constant            &       13.66\sym{***}&       58.99\sym{***}&       60.07\sym{***}&       64.76\sym{***}\\
                    &     (84.14)         &    (541.52)         &    (478.00)         &    (667.77)         \\
\midrule
Observations        &      {386364}         &      {386364}         &      {386364}         &      {386364}         \\
\bottomrule
\multicolumn{5}{l}{\footnotesize \textit{t} statistics in parentheses}\\
\multicolumn{5}{l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
\end{tabular}
\end{table}



\end{document}
1
  • Thank you very much for the work and patience! That works perfectly for what I was looking for!
    – pfragon
    Dec 20, 2020 at 12:21
4
\begin{tabular*}{1.1\hsize}{@{\hskip\tabcolsep\extracolsep\fill}l*{4}{D{.}{.}{-1}}}

specifies that latex should stretch the table so the columns are far apart and the total width of the table is 10% wider than fits on the page.

use

\begin{tabular}{l*{4}{D{.}{.}{-1}}}

So that the table is natural width.

2
  • Thank you again for your reply, that does seem to work, but I want to narrow down the space between columns. Any way to do that by changing from tabular* to tabular?
    – pfragon
    Dec 20, 2020 at 12:13
  • @pfragon that presumably already makes the space between columns less as you are no longer stretching the table but you can put \setlength\tabcolsep{1pt} immediately before \begin{tabular} if you want to squeeze it more or replace -1 by 2.8 or whatever format works best in the D column specification. Dec 20, 2020 at 12:16

You must log in to answer this question.

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