2

Inspired by the following post \bfseries and alignment in table, I want to create a table where some of the entries are highlighted in bold, and further, the numbers should be aligned on the dot. I defined the boldentry command as desribed on the post, but for some reason the numbers are not perfectly aligned in this case. What is the problem in the code below?

\documentclass[b5paper,10pt,authoryear,longnamesfirst]{memoir}
\usepackage{booktabs,siunitx}
\usepackage[flushleft]{threeparttablex}
\newcommand{\MS}[1] {
    \multicolumn{1}{c}{#1}}
\newcommand{\boldentry}[2]{%
    \multicolumn{1}{S[table-format=#1,
                mode=text,
                text-rm=\fontseries{b}\selectfont
               ]}{#2}}
\begin{document}

\sisetup{detect-weight=true,detect-inline-weight=math}

\begin{table}
\scriptsize
\caption{A caption}
\begin{threeparttable}
\begin{tabular*}{\textwidth}{l@{\extracolsep{\fill}}*{9}{S[table- 
    format=1.3]}}
\toprule
        & \MS{A} & \MS{B} & \MS{C} & \MS{D} & \MS{E} & \MS{F} & \MS{G} & 
          \MS{H} & \MS{I}\\
\midrule

     A & \boldentry{1.3}{1.004}&\boldentry{1.3}{1.000}&\boldentry{1.3} 
     {1.008}&\boldentry{1.3}{1.000}&\boldentry{1.3}{0.989}&\boldentry{1.3} 
     {1.008}&1.070  & \boldentry{1.3}{0.981}&1.025\\

     B & 1.025  & 1.012  & 1.016  & \boldentry{1.3}{1.000}&\boldentry{1.3} 
     {0.967}&\boldentry{1.3}{0.968}&\boldentry{1.3}{0.982}&\boldentry{1.3} 
     {0.961}&1.077\\

     C& 1.009  & 1.001  & 1.002  & 1.000  & 0.986  & 0.985  & 0.991  & 
     \boldentry{1.3}{0.973}&0.998\\

     D & 1.009  & 1.010  & 1.001  & 1.000  & 0.951  & 0.959  & 0.975  & 
     \boldentry{1.3}{0.931}&1.015\\
    \bottomrule

\end{tabular*}
\begin{tablenotes}
\setlength\labelsep{0pt}
\scriptsize
\item A footnote  
\end{tablenotes}
\end{threeparttable}
\end{table}

\end{document}

enter image description here

  • Observation: if you add \scriptsize to egreg's code in the post you linked, his table is not aligned either... It might be because at script size, bold numbers are actually significantly narrower than normal ones (it's even more visible with \tiny). – Inquisitive Lurker Jan 10 at 14:07
2

enter image description here

i remove your definition \newcommand{\boldentry}[2]{...}, add the package etoolbox for robust new command \B which is used to indicate the cells that have bold faced numbers. LL CHanges in comparison to your mwe are indicated in code by % <--:

\documentclass[b5paper,10pt,authoryear,longnamesfirst]{memoir}
\usepackage{booktabs}
\newcommand\mcc[1]{\multicolumn{1}{c}{#1}} % instead of \MS. you can still use your command ...
\usepackage{siunitx}
\usepackage[flushleft]{threeparttablex}

\usepackage{etoolbox}           % <--
\renewcommand{\bfseries}{\fontseries{b}\selectfont} % <--
\robustify\bfseries             % <--
\newrobustcmd{\B}{\bfseries}    % <--


\begin{document}
    \begin{table}
    \small
    \caption{A caption}
    \setlength\tabcolsep{0pt}
\begin{threeparttable}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}
        l
    *{9}{S[detect-weight,   % <--
           mode=text,       % <--
           table-format=1.3]}}
\toprule
    & \mcc{A}   & \mcc{B}   & \mcc{C}   & \mcc{D}   & \mcc{E}
    & \mcc{F}   & \mcc{G}   & \mcc{H}   & \mcc{I}       \\
\midrule
A   & \B 1.004  & \B 1.000  & \B 1.008  & \B 1.000  & \B 0.989
    & \B 1.008  &    1.070  & \B 0.981  &    1.025      \\
B   &   1.025   &    1.012  &    1.016  & \B 1.000  & \B 0.967
    & \B 0.968  & \B 0.982  & \B 0.961  &    1.077      \\
C   &    1.009  &    1.001  &    1.002  &    1.000  &    0.986
    &    0.985  &    0.991  & \B 0.973  &    0.998      \\
D   &    1.009  &    1.010  &    1.001  &    1.000  & 0.951
    &    0.959  &    0.975  & \B 0.931  &    1.015      \\
    \bottomrule
\end{tabular*}
\begin{tablenotes}
\setlength\labelsep{0pt}
\scriptsize
\item A footnote
\end{tablenotes}
\end{threeparttable}
\end{table}

\end{document}
  • 1
    @mico, ups, i forgot to add two more lines for boldface text. corrected now. thank you very much for pointing me on this. – Zarko Jan 10 at 14:22

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.