6

I am looking for help regarding number alignment along the decimal point.

Here is the code that I use so far:

\documentclass{article}
\usepackage{etoolbox, siunitx}
\usepackage{booktabs,makecell}
\sisetup{input-symbols = {()},
 group-digits  = false,
 table-sign-mantissa,
 table-space-text-post = *,
 parse-numbers=false,
 detect-weight=true,
 detect-shape=true,
 detect-mode=true
 }
\begin{document}
\begin{table*}[]
\robustify\bfseries
\caption{My-caption}
\centering
\setlength{\tabcolsep}{8pt}
\begin{tabular}{@{} S[table-format=4.4, detect-all] lS[table-format=4.4,           
 detect-all]>{\bfseries} S[table-format=4.4, detect-weight] S[table-     
 format=4.4, detect-weight] @{}} 
\toprule
   &\multicolumn{1}{c}{{Low}}  &  & \multicolumn{1}{c}{Med} \\ \midrule                           

  MV    & 1.64    & 1.14    &  1.58   \\                                                                        
        & (1.17)  & (0.97)  &  (0.87) \\                                           
  AG    & 2.61    & 1.36    &  1.07   \\                                 
        & (1.17)  & (0.88)  &  (0.64)  \\   
  BM    & 2.08    & 1.14    &  0.44    \\                                               
        & (0.98)  & (0.86)  &  (0.29)  \\   
  MOM   & 0.74    & 0.28    &  -0.34   \\                                         
        & (0.31)  & (0.12)  &  (-0.17)   \\                                            
  TA    & \bfseries 1.90 & 1.03  &  0.88 \\                                                         
        & (1.63)   & (1.75)  &  (1.06)    \\                                                  
\Xhline{3\arrayrulewidth}
\end{tabular}
\end{table*}
\end{document}

And here is the output:

enter image description here

I want the numbers to be aligned by decimal point, but want to highlight some of them in bold without having the alignment crashed like this.

4
  • Add the \documentclass and \begin{document} /\end{document} so that we can compile the example without have first to edit it. Commented Jul 7, 2016 at 10:03
  • Welcome to TeX.SE! adding to what Ulrike Fischer said add \usepackage{makecell} oterwise \Xhline is not reconized.
    – Cfun
    Commented Jul 7, 2016 at 10:05
  • 2
    See if my answer on question tex.stackexchange.com/questions/275324/… can help you.
    – Zarko
    Commented Jul 7, 2016 at 10:13
  • Thanks, Zarko for your comment! I includes \usepackage{threeparttable} and \roubstify\ubold - my numbers are aligned but the respective number is not bold...
    – Funnybunny
    Commented Jul 7, 2016 at 11:08

2 Answers 2

8

I assume that your answer is actually continuation of your question (I suggest to edit your question and move it there).

Problem in aligning of cells content and boldface fonts for some of them is in option parse-numbers=false. Without it all with exception of cells of form (-0.01) works as expected, those cells generate errors. This can be prevented by putting them into curly braces: {(-0.03)}, however it is not aligned as desired anymore.

For the particular case of table in question, can be used dirty trick shown in the code below, which mitigate this problem. See, if result is satisfactory.

\documentclass[preview,border=1pt]{standalone}
\usepackage{booktabs}
\usepackage{siunitx}

\usepackage{etoolbox}% <-- new
\newcommand{\ubold}{\fontseries{b}\selectfont} % renew def. for non-extended bold font
\robustify\ubold

\newcommand\mc[1]{\multicolumn{1}{c}{#1}}
\begin{document}
    \begin{table}
\caption{My Caption}
\centering
    \begin{tabular}{ l *{6}{S[input-symbols = {()},
                              table-space-text-post=\ ,% <-- for spacing of )
                              detect-weight,
                              table-format=-1.2]}}
    \toprule
\multicolumn{7}{c}{Panel A: Univariate Sorts Based on $\beta_{\sigma,t}$}                   \\ \midrule
       & \mc{Low}       &           & \mc{Med}  &           & \mc{High} &  \mc{High-Low}    \\ \midrule
   MV  & 1.64           & 1.14      &  1.58     & 1.08      & 1.45      &                   \\
       & (1.17)         & (0.97)    &  (0.87)   & (0.64)    & (1.03)    &                   \\
  TA   & \ubold 1.90    & 1.03      &  0.88     & 0.87      & 1.35      &                   \\
       & (1.63)         & (1.75)    &  (1.06)   & (0.43)    & {(-0.03)} % <--- here is problem
                                                                        &     {~~~}         \\
   \bottomrule
    \end{tabular}
    \end{table}
\end{document}

Result:

enter image description here

Trick is in added space for right parenthesize in column formatting.

Addendum After three years I would write this table as follows:

\documentclass[preview,border=1pt]{standalone}
\usepackage{booktabs}
\usepackage{siunitx}

\usepackage{etoolbox}   % <-- new
\usepackage{xparse}     % <-- new
\NewExpandableDocumentCommand\mc{O{1}m} % <--
    {\multicolumn{#1}{c}{#2}}

\begin{document}
    \begin{table}
\sisetup{input-open-uncertainty= ,  % <-- new
         input-close-uncertainty= , % <-- new
         table-space-text-pre=(,    % <-- new
         table-space-text-post=),   % <-- new
         table-align-text-pre=false,% <-- new
         detect-weight,
         mode=text,                 % <-- new
         table-format=-1.2}
\renewcommand{\bfseries}{\fontseries{b}\selectfont} % <-- new
\newrobustcmd{\B}{\bfseries}                        % <-- changed
    \caption{My Caption}
    \centering
\begin{tabular}{ l *{6}{S} }        % <--- changed
    \toprule
\mc[7]{Panel A: Univariate Sorts Based on $\beta_{\sigma,t}$}       \\
    \midrule
    &\mc{Low}&        &\mc{Med}&        &\mc{High}& \mc{High-Low}   \\
    \midrule
MV  & 1.64   & 1.14   &  1.58  &  1.08  &   1.45  &   \\
    & (1.17) & (0.97) & (0.87) & (0.64) & ( 1.03) &   \\
\addlinespace
TA  &\B 1.90 & 1.03   &  0.88  &  0.87  &   1.35  &   \\
    & (1.63) & (1.75) & (1.06) & (0.43) & (-0.03) &   \\    % <--- changed
   \bottomrule
\end{tabular}
    \end{table}
\end{document} 

All changes in comparison to original code are marked by % <---. Result now has more consistent appearance (correct align at decimal points, correct minus sign, width of boldface digits ares equal to normal ones):

enter image description here

1
  • This works beautifully! Thank you very, very much :-)
    – Funnybunny
    Commented Jul 7, 2016 at 14:42
0

I implemented the suggestion by Zarko:

\documentclass[preview,border=1pt]{standalone}
\usepackage{booktabs,threeparttable,caption,siunitx}
\usepackage{etoolbox}% <-- new
\sisetup{input-symbols = {()},
group-digits  = false,
table-space-text-post = *,
parse-numbers=false,
}

\newcommand{\ubold}{\fontseries{b}\selectfont} % renew def. for non-extended bold font
\begin{document}
\begin{table}
\caption{My Caption}
\centering
\begin{threeparttable}
 \setlength{\tabcolsep}{8pt}
\begin{tabular}{ l *{7}{S[detect-weight,table-format=4.4]}} 
\toprule
\multicolumn{7}{c}{Panel A: Univariate Sorts Based on $\beta_{\sigma,t}$}                                                                                                                                                                              \\ \midrule
&\multicolumn{1}{c}{{Low}}  &  & \multicolumn{1}{c}{Med}   &  & \multicolumn{1}{c}{High}    &  \multicolumn{1}{c}{High-Low}         \\ \midrule
   MV  & 1.64   & 1.14  &  1.58  & 1.08  & 1.45 &   \\                
       & (1.17) & (0.97)  &  (0.87) & (0.64) & (1.03) &  \\            
  TA   & \ubold 1.90   & 1.03 &  0.88 & 0.87  & 1.35  & \\                
       & (1.63) & (1.75)  &  (1.06)  & (0.43) & (-0.03)&  \\           
   \bottomrule
    \end{tabular}
    \end{threeparttable}
    \end{table}
    \end{document}

But I get the following output:enter image description here

Does anybody see my mistake?

6
  • you miss/forgot on main command in preamble of my answer: \robustify\ubold which had to follows \newcommand{\ubold}{...}
    – Zarko
    Commented Jul 7, 2016 at 12:11
  • @Zarko as i tested previously it doesn't work in this case, because there isn't just numbers
    – Cfun
    Commented Jul 7, 2016 at 12:17
  • I added \robustify\ubold after the command \newcommand{\ubold}{...} - but unfortunately, this does not do the trick :-(
    – Funnybunny
    Commented Jul 7, 2016 at 12:18
  • There is conflict between options in \sisetup, temporary I haven't time to look closely, what can be done. Maybe latter evening ...
    – Zarko
    Commented Jul 7, 2016 at 12:50
  • Your help would be very much appreciated, Zarko!
    – Funnybunny
    Commented Jul 7, 2016 at 13:03

You must log in to answer this question.

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