Column Spacing and Multicolumn Alignment

dcolumnmulticolumnspacing

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!

Best Answer

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.

Related Question