1

I am trying to right-align a multicolumn table heading, where one of the columns it straddles is aligned on a decimal point with dcolumn, and the other is left-aligned. In the example below, I would like the closing bracket of "Difference (p-value)" to be flush with the closing brackets of the column below it. I have fiddled with spacing between columns and creative mixing of the general alignment "rcl" etc. Does anyone have other tips?

\documentclass{article}
\usepackage{dcolumn} 
\newcolumntype{Q}{D{.}{.}{2}}

\begin{document}
\begin{tabular}{lQQQ@{\hspace{0.1em}}l}
  \hline
  Variable & \multicolumn{1}{c}{Period 1} & \multicolumn{1}{c}{Period 2} & \multicolumn{2}{r}{Difference (p-value)}  \\ 
  \hline
 var0 & 6.00 & 8.00 & 2.00 & (0.00) \\ 
  var1 & 0.61 & 0.73 & 0.12 & (0.00) \\ 
   var2 & 359.00 & 404.00 & 44.43 & (0.03) \\ 

   \hline
   \end{tabular}
\end{document}
3
  • Welcome to TeX SX! Do you have specific reasons for such a thin space between columns 3 and 4?
    – Bernard
    Oct 5 '19 at 13:04
  • Welcome to TeX.SE! What meaning has numbers in the last(fifth) column? Are they uncertainty of values in the fourth column? If they are, they notation is wrong, on such a way they can not be decimal numbers. With decimal numbers you can write as for example 2.00 \pm 0.00.
    – Zarko
    Oct 5 '19 at 13:04
  • Thanks for the questions. The numbers in parantheses are p-values from a t-test of the difference between the columns. I do not want them to be separate columns because there are a few tables where I will have more than one of these difference(p-value) columns.
    – serwaah
    Oct 5 '19 at 16:40
0

Some guessing what you like to have (with use of the siunitx package instead of dcolumn):

\documentclass{article}
\usepackage{siunitx}


\begin{document}
\begin{tabular}{l*{2}{S[table-format=3.2]}
                      S[table-format=2.2(1),
                        table-alignment=right,
                        separate-uncertainty,
                        ] 
                }
  \hline
  Variable  & {Period 1} & {Period 2} & {Difference (p-value)}  \\
  \hline
 var0       &   6.00    &   8.00    &  2.00(0)   \\
 var1       &   0.61    &   0.73    &  0.12(0)   \\
 var2       & 359.00    & 404.00    & 44.43(3)   \\
   \hline
   \end{tabular}

\bigskip
\begin{tabular}{l*{2}{S[table-format=3.2]}
                      S[table-format=2.2(1),
                        table-alignment=right,
                        ]
                }
  \hline
  Variable  & {Period 1} & {Period 2} & {Difference (p-value)}  \\
  \hline
 var0       &   6.00    &   8.00    &  2.00(0)   \\
 var1       &   0.61    &   0.73    &  0.12(0)   \\
 var2       & 359.00    & 404.00    & 44.43(3)   \\
   \hline
   \end{tabular}

\bigskip
\begin{tabular}{l*{2}{S[table-format=3.2]}
                      S[table-format=8.0,
                        ]
                      %@{\hskip-2em}
                      S[table-format=1.2,
                        table-space-text-pre=\,(,
                        table-space-text-post=),
                        input-symbols = {( )}
                        ]
                }
  \hline
  Variable  & {Period 1} & {Period 2} & \multicolumn{2}{r}{Difference (p-value)}  \\
  \hline
 var0       &   6.00    &   8.00    &  2.00 & (0.00)   \\
 var1       &   0.61    &   0.73    &  0.12 & (0.00)   \\
 var2       & 359.00    & 404.00    & 44.43 & (0.03)   \\
   \hline
   \end{tabular}
\end{document}

Correct notations are in the first two examples.

enter image description here

However, I would wrote p value as separate column:

enter image description here

\documentclass{article}
\usepackage{siunitx}


\begin{document}
    \begin{tabular}{l *{2}{ S[table-format=3.2] }
                            S[table-format=2.2]
                            S[table-format=1.2,
                              table-space-text-pre={\,(},
                              table-space-text-post=),
                              input-symbols = {( )}]
                            }
  \hline
  Variable  & {Period 1} & {Period 2} & {Difference} & {(p-value)}  \\
  \hline
 var0       &   6.00    &   8.00    &  2.00 & (0.00)   \\
 var1       &   0.61    &   0.73    &  0.12 & (0.00)   \\
 var2       & 359.00    & 404.00    & 44.43 & (0.03)   \\
   \hline
   \end{tabular}
\end{document}
1
  • Thank you! Versions 2 and 3 get to what I want.
    – serwaah
    Oct 5 '19 at 17:07

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.