1

I have the following problem: I would like to have a larger column spacing in the middle of my table in order to visually separate two different model specifications. I generally use dcolumn and multicolumn to create my table. Then I used \extracolsep in order to enforce different column spaces. However, this also messes with the \multicolumn spacing and I end up with a missaligned table.

MWE:

\documentclass[]{article}
\usepackage{dcolumn,tabularx,float}

\title{Minimum Working Example}
\author{Methamortix}

\begin{document}

\maketitle

\begin{abstract}
How to tex a beautiful tables.
\end{abstract}

\section{the MWE}

\begin{table}[H] \centering 
    \caption{A nice table } 
    \label{} 
    \tiny 
    \begin{tabular}{@{\extracolsep{-5pt}} lD{.}{.}{-3} @{\extracolsep{-10pt}} D{.}{.}{-3}@{\extracolsep{-10pt}} D{.}{.}{-3}@{\extracolsep{10pt}} D{.}{.}{-3} @{\extracolsep{-10pt}} D{.}{.}{-3} @{\extracolsep{-10pt}} D{.}{.}{-3} } 
        \\[-1.8ex]\hline 
        \hline \\[-1.8ex] 
        & \multicolumn{6}{c}{\textit{Dependent variable:}} \\ 
        \cline{2-7} 
        \\[-1.8ex] & \multicolumn{6}{c}{ } \\ 
        & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} \\ 
        \\[-1.8ex] & \multicolumn{1}{c}{(1)} & \multicolumn{1}{c}{(2)} & \multicolumn{1}{c}{(3)} & \multicolumn{1}{c}{(4)} & \multicolumn{1}{c}{(5)} & \multicolumn{1}{c}{(6)}\\ 
        \hline \\[-1.8ex] 
        Medicine A & 0.999^{**} & 0.888 & 0.777^{**} & 0.666^{***}  & 0.555 & 0.444 \\ 
        & (0.111) & (0.222) & (0.333) & (0.444) & (0.555) & (0.666) \\ 
        & & & & & & \\ 
        Medicine B & 1.555 & 1.666^{***} & 1.777 & 1.888^{***} & 1.999 & 2.000^{*} \\ 
        & (0.111) & (0.222) & (0.333) & (0.444) & (0.555) & (0.666) \\ 
        & & & & & & \\ 

        \hline \\[-1.8ex] 
        Observations & \multicolumn{1}{c}{200000} & \multicolumn{1}{c}{200000} & \multicolumn{1}{c}{200000} & \multicolumn{1}{c}{200000} & \multicolumn{1}{c}{200000} & \multicolumn{1}{c}{200000} \\ 
        Adjusted R$^{2}$ & \multicolumn{1}{c}{0.50} & \multicolumn{1}{c}{0.50} & \multicolumn{1}{c}{0.50} & \multicolumn{1}{c}{0.50} & \multicolumn{1}{c}{0.50} & \multicolumn{1}{c}{0.50} \\ 
        \hline 
        \hline \\[-1.8ex] 
        \textit{Note:}  & \multicolumn{6}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\ 
    \end{tabular} 
\end{table}
\end{document}

This gives the following result:

enter image description here

As you can see the alignment of the column names and the number of observations and goodness of fit measure are now messed up.

Has someone some insights on how to fix this problem? Or maybe a different solution to end up with a space separation between column 3 and 4?

Thanks a lot!

5
  • Welcome to TSE. Please post a Minimal Working Example, instead of a code snippet. Oct 12, 2021 at 9:55
  • I am sorry. Is it fine now? Oct 12, 2021 at 10:02
  • 1
    Insert @{\qquad} between columns, which you like to have more apart.
    – Zarko
    Oct 12, 2021 at 10:04
  • Yes, it is fine now. Oct 12, 2021 at 10:08
  • @Zarko If I use @{\qquad} instead of {\extracolsep{-15pt}} then I have exactly the same issue. Oct 12, 2021 at 10:08

1 Answer 1

1

Your table code is quite unusual. I would rather write your table on the following way:

\documentclass[]{article}
\usepackage{siunitx} % new, used is version v3.0.32, last revised 2021-09-29.
\usepackage{booktabs, tabularx} % new
\usepackage[referable]{threeparttablex} % new

\begin{document}
    \begin{table}[ht]
    \begin{threeparttable}
    \caption{A nice table }
    \label{tab:may beautiful table}
\sisetup{table-format = {(}-1.3,          % <---
         input-open-uncertainty = ,
         input-close-uncertainty = ,
         table-align-text-before = false, % <---
         table-space-text-post =$^{***}$  % <---
         }
\small
\setlength\tabcolsep{1pt}
\begin{tabularx}{\linewidth}{@{} X *{3}{S} @{\hspace{1em}}  *{3}{S} @{}}
    \toprule
    & \multicolumn{6}{c}{\textit{Dependent variable:}}          \\
    \cmidrule(l){2-7}
    & {(1)} & {(2)}     &  {(3)} &  {(4)}   &  {(5)} & {(6)}    \\
    \midrule
Medicine A 
    & 0.999\tnote{**}   & -0.888            & 0.777\tnote{**}   % <---
    & 0.666\tnote{***}  & 0.555             & 0.444             \\
    & (0.111)           & (-0.222)          & (0.333)           % <---
    & (0.444)           & (0.555)           & (0.666)           \\
    \addlinespace
Medicine B 
    & 1.555             & 1.666\tnote{***}  & 1.777 
    & 1.888\tnote{***}  & 1.999             & 2.000\tnote{*}    \\
    & (0.111)           & (0.222)           & (0.333)           
    & (0.444)           & (0.555)           & (0.666)           \\
    \addlinespace
Observations 
    & {200000}          & {200000}          & {200000} 
    & {200000}          & {200000}          & {200000}          \\
Adjusted $\mathrm{R}^{2}$ 
    & {0.50}            & {0.50}            & {0.50} 
    & {0.50}            & {0.50}            & {0.50}            \\
    \bottomrule
\end{tabularx}\footnotesize
    \begin{tablenotes}[para]
    \note: \item[*:] $p<0.1$; \item[**:] $p<0.05$; \item[***:] $p<0.05$ 
    \end{tablenotes}
\end{threeparttable}
    \end{table}
\end{document}

enter image description here

Edit: Added example of use sign - in table.

3
  • Thanks a lot. I started to look into siunitx and it will be my to go way to format tables now! Oct 12, 2021 at 11:10
  • I am sorry I am trying to understand your example. However, I have noticed that the table blows up if I use negative numbers. Then I tried to fix it by setting "table-format = {(}1.3{)}" to "table-format = {(}2.3{)}, but it does not work. Can you maybe help me to understand how to work in this environmentwith negative numbers? Oct 12, 2021 at 16:19
  • 1
    @Methamortix, it is possible to use negative numbers :-), however you need accordingly set-up siunitx Consult package documentation or wait on my spare time late evening or tomorrow (CET) early morning :-)
    – Zarko
    Oct 12, 2021 at 17:50

You must log in to answer this question.

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