0

I have the following MWE:

\documentclass[12pt, a4paper]{article}
\usepackage[english]{babel}


\usepackage{amsmath}
\usepackage{amssymb} 
\usepackage{amsthm}

\usepackage{tabularx}
\usepackage{array}
\usepackage{caption}

\usepackage{booktabs, siunitx}
\usepackage{dcolumn}
\NewExpandableDocumentCommand\mcc{O{1}m}
    {\multicolumn{#1}{c}{#2}}

\begin{document}    

\begin{table}[h!]
\begin{scriptsize}
\centering
\caption{Caption}
\setlength{\tabcolsep}{3pt}
\renewcommand{\arraystretch}{1.10}
\begin{tabular*}{\linewidth}{l @{\extracolsep{\fill}}*{3}{D{.}{.}{6}}}
\toprule
& \mcc[1]{Col A}
& \mcc[1]{Col B} 
& \mcc[1]{Col C} \\
\midrule

\multicolumn{4}{l}{\textbf{Panel A: This is model 1}}\\
\midrule
ABC  &-1.23^{***}  &-6.12   &-4.32^{*}\\
     &(-9.01)      &(-3.32) &(6.12)
\\
DEF  &-4.12        &7.01    &-0.71\\
     &(1.54)       &(0.02)  &(-1.52)

\\
\multicolumn{4}{l}{\textbf{Panel B: This is model 2 that has a longer name than model 1}}\\
\midrule
ABC  &-0.64^*   &-0.52      &-6.01^{**}\\
     &(-1.86)   &(-7.13)    &(-9.43)   \\
DEF  &-0.23     &0.01       &-6.71  \\
     &(-0.43)   &(3.12)     &(-3.52)\\
\bottomrule
\end{tabular*} 
\end{scriptsize}
\end{table}


\end{document}

The only issue I have with this table is that the column-labels are not aligned with the entries, see the markings below:

enter image description here

I noticed that it is because the caption Panel B: This is model 2 that has a longer name than model 1 is long. Is there a way to keep the caption as is, but align the entries with the column-name Col C?

3
  • Does \mcc[1] do anything? Why not just take that out? – Teepeemm Feb 8 at 14:30
  • @Teepeemm I tried, but then the columns will not be evenly spaced – Tyler D Feb 8 at 14:34
  • 1
    you have tabularx in the title and tagged the question that way but your example does not use tabularx at all it uses the standard tabular* environment – David Carlisle Feb 8 at 15:12
1

This is unrelated to tabularx, you are using the standard tabular*.

personally I would use a tabular here as forcing the table to be full width just makes the columns further apart and the table harder to read (this is almost always the case for any table)

But if you you do want the table full width, you can hide the width of the spanning entries so the width is allocated equally between each column

enter image description here

\documentclass[12pt, a4paper]{article}
\usepackage[english]{babel}


\usepackage{amsmath}
\usepackage{amssymb} 
\usepackage{amsthm}

% not used \usepackage{tabularx}
\usepackage{array}
\usepackage{caption}

\usepackage{booktabs, siunitx}
\usepackage{dcolumn}
\NewExpandableDocumentCommand\mcc{O{1}m}
    {\multicolumn{#1}{c}{#2}}

\begin{document}    

\begin{table}[htp]% only use ! and h in very special "after all editing complete" emergency situations
\begin{scriptsize}
\centering
\caption{Caption}
\setlength{\tabcolsep}{3pt}
\renewcommand{\arraystretch}{1.10}

\begin{tabular*}{\linewidth}{l @{\extracolsep{\fill}}*{3}{D{.}{.}{6}}}
\toprule
& \mcc[1]{Col A}
& \mcc[1]{Col B} 
& \mcc[1]{Col C} \\
\midrule

\multicolumn{4}{l}{\rlap{\textbf{Panel A: This is model 1}}}\\
\midrule
ABC  &-1.23^{***}  &-6.12   &-4.32^{*}\\
     &(-9.01)      &(-3.32) &(6.12)
\\
DEF  &-4.12        &7.01    &-0.71\\
     &(1.54)       &(0.02)  &(-1.52)

\\
\multicolumn{4}{l}{\rlap{\textbf{Panel B: This is model 2 that has a longer name than model 1}}}\\
\midrule
ABC  &-0.64^*   &-0.52      &-6.01^{**}\\
     &(-1.86)   &(-7.13)    &(-9.43)   \\
DEF  &-0.23     &0.01       &-6.71  \\
     &(-0.43)   &(3.12)     &(-3.52)\\
\bottomrule
\end{tabular*} 
\end{scriptsize}
\end{table}


\end{document}
1

With tabularx:

\documentclass[12pt, a4paper]{article}
\usepackage[english]{babel}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}

\usepackage{booktabs, tabularx}
\NewExpandableDocumentCommand\mcx{O{1}m}
    {\multicolumn{#1}{>{\centering\arraybackslash}X}{#2}}
\NewExpandableDocumentCommand\mclbf{O{1}m}
    {\multicolumn{#1}{>{\bfseries}l}{#2}}
\usepackage{caption}

\usepackage{siunitx}

\begin{document}
    \begin{table}[ht]
\sisetup{input-open-uncertainty= ,   
         input-close-uncertainty= , 
         table-space-text-pre=(,     
         table-space-text-post=***,   
         table-format=-1.2}
    \centering
\caption{Caption}
\renewcommand{\arraystretch}{1.10}
\begin{tabularx}{\linewidth}{ l *{3}{S} }
    \toprule
    & \mcx{Col A}       &   \mcx{Col B}     
                                    &   \mcx{Col C} \\
    \midrule
\mclbf[4]{Panel A: This is model 1}                 \\
    \midrule
ABC  &  -1.23$^{***}$   &  -6.12    &  -4.32$^{*}$  \\
     & (-9.01)          & (-3.32)   &  (6.12)       \\
DEF  &  -4.12           &  7.01     &  -0.71        \\
     &  (1.54)          & (0.02)    & (-1.52)       \\
\mclbf[4]{Panel B: This is model 2 
         that has a longer name than model 1}       \\
\midrule
ABC  &  -0.64$^{*}$     &  -0.52    &  -6.01$^{**}$ \\
     & (-1.86)          & (-7.13)   & (-9.43)       \\
DEF  &  -0.23           &   0.01    &  -6.71        \\
     & (-0.43)          &  (3.12)   & (-3.52)       \\
\bottomrule
\end{tabularx}
    \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.