[Tex/LaTex] \bfseries and alignment in table

boldhorizontal alignmentsiunitxtablestabularx

I'm trying to highlight some decimal-point aligned entries in two large tables which are arranged in two columns. I'm using \bfseries to do this and unfortunately this seems to be affecting the alignment. I have read the documentation and have made \bfseries robust by prepending \robustify, however the result is still somewhat misaligned. Here is an example which contains a small part of the table:

\documentclass{article}

\usepackage{comment}

\usepackage[left=1.5cm, right=1.5cm]{geometry}
\usepackage{subcaption}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{ragged2e}
\usepackage{etoolbox,siunitx}

\begin{document}

\begin{table}
  \begin{subtable}[b]{0.47\textwidth}
  \resizebox{1\textwidth}{!}
  {%
    \large
    \robustify\bfseries
    \sisetup{detect-weight=true,detect-inline-weight=math}
    \begin{tabular}{S[table-format=1.2(2)]S[table-format=1.2(2)]S[table-format=2.2(2)]S[table-format=2.2(2)]}
    \toprule
        1.68(2) & 2.66(16) & 8.39(12) & 13.11(25)\\
        0.95(1) & 1.38(4)  & 4.64(18) &  9.76(32)\\
        0.80(1) & 1.18(5) & 7.52(31) & 12.64(24)\\
        0.95(1) & 1.32(3) & 3.13(15) & \bfseries 8.68(29)\\
        0.21(0) & 0.30(1) & 5.59(63) & 12.07(23)\\
        0.36(0) & 0.50(1) & \bfseries 1.26(16) &  9.42(57)\\
        0.15(0) &  0.22 (1) & 3.49(98) & 12.19(34)\\
      \cmidrule(l{\dimexpr 0.5em}r{\dimexpr 0.5em}){1-4}
        0.83(1) & 1.22(5) & \bfseries 5.08(26) & \bfseries 10.95(32)\\
    \bottomrule
    \end{tabular}
  }
  \end{subtable}
  \hspace{0.05\textwidth}
  \begin{subtable}[b]{0.47\textwidth}
  \resizebox{1\textwidth}{!}
  {%
    \large
    \robustify\bfseries
    \sisetup{detect-weight=true,detect-inline-weight=math}
    \begin{tabular}{S[table-format=1.2(2)]S[table-format=1.2(2)]S[table-format=2.2(2)]S[table-format=2.2(2)]}
    \toprule
        \bfseries 1.68(2) & \bfseries 2.66(1) & 8.39(12) & 13.11(25)\\
        0.95(1) & 1.38(4)  & 4.64(18) &  9.76(32)\\
        0.80(1) & 1.18(5) & 7.52(31) & 12.64(24)\\
        0.95(1) & 1.32(3) & 3.13(15) & 8.68(29)\\
        0.21(0) & 0.30(1) & 5.59(63) & 12.07(23)\\
        0.36(0) & 0.50(1) & 1.26(16) &  9.42(57)\\
        0.15(0) &  0.22 (1) & 3.49(98) & 12.19(34)\\
      \cmidrule(l{\dimexpr 0.5em}r{\dimexpr 0.5em}){1-4}
        0.83(1) & 1.22(5) & \bfseries 5.08(26) & \bfseries 10.95(32)\\
      \bottomrule
    \end{tabular}
  }
  \end{subtable}
\end{table}


\end{document}

This is the result I get, the decimal points are not aligned. Any ideas how to fix this? I'm using TexLive 2012 installed via the Ubuntu package manager.

Best Answer

You can use a non extended bold, but you also have to override the setup for the cell.

The command \boldentry takes as arguments the digit specification for the cell and the number to typeset.

\documentclass{article}

\usepackage{siunitx,booktabs}

\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{tabular}{
  S[table-format=1.2(2)]
  S[table-format=1.2(2)]
  S[table-format=1.2(2)]
  S[table-format=2.2(2)]
}
\toprule
1.68(2) & 2.66(16) & 8.39(12) & 13.11(25)\\
0.95(1) & 1.38(4)  & 4.64(18) &  9.76(32)\\
0.80(1) & 1.18(5) & 7.52(31) & 12.64(24)\\
0.95(1) & 1.32(3) & 3.13(15) & \boldentry{2.2(2)}{8.68(29)}\\
0.21(0) & 0.30(1) & 5.59(63) & 12.07(23)\\
0.36(0) & 0.50(1) & \boldentry{1.2(2)}{1.26(16)} &  9.42(57)\\
0.15(0) &  0.22 (1) & 3.49(98) & 12.19(34)\\
\cmidrule(l{\dimexpr 0.5em}r{\dimexpr 0.5em}){1-4}
0.83(1) & 1.22(5) & \boldentry{1.2(2)}{5.08(26)} & \boldentry{2.2(2)}{10.95(32)}\\
\bottomrule
\end{tabular}

\end{document}

enter image description here

Related Question