2

I've been trying to get some entries in my table typeset in boldface while using siunitx for the proper alignment.

I've tried numerous other answers I found on the web, but the issue I have is that I want the numbers to be rendered in the math font, not the main font.

This is the current minimal example code for my problem:

%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode

\documentclass[12pt,a4paper,oneside]{memoir}

\usepackage{mathtools}
\usepackage{babel}  % Language hyphenation and typographical rules
\usepackage{csquotes}  % Context sensitive quotation facilities
\usepackage{microtype}  % Slightly tweak font spacing for aesthetics
\usepackage[warnings-off={mathtools-colon}]{unicode-math}
\usepackage{siunitx}
\usepackage{booktabs, longtable}  % Better looking tables
\usepackage{etoolbox}

\setmainfont{EBGaramond-Regular}
\setmathfont{STIX Two Math}

\begin{document}

\begin{table}[t]
    \centering
    \robustify\bfseries
    \sisetup{detect-weight, separate-uncertainty, group-minimum-digits = 4}
    \begin{tabular}
        {l S[table-format=3.2(1)] S[table-format=2.0] S[table-format=3.2(1)] S[table-format=3.0]}
        \toprule
                       & \multicolumn{2}{c}{{Point-mass}}          & \multicolumn{2}{c}{{Pendulum}} \\
                       \cmidrule(lr){2-3}                        \cmidrule(lr){4-5}
                       & {Cost $(\mu \pm \sigma)$} & {Succ.$^\dag$} & {Cost $(\mu \pm \sigma)$} & {Succ.$^\ddag$} \\
        \midrule
        {mppi}$^\S$ & {---}                   & {---}                        & 30.8 +- 12.6            & 100\unit{\percent} \\
        {disco}     & 250.8 +- 29.9           & 20\unit{\percent}            & 61.3 +- 40.0            &  70\unit{\percent} \\
        {svmpc}     & 191.7 +- 56.5           & 25\unit{\percent}            & 44.5 +- 17.9            &  70\unit{\percent} \\
        {dust}      & \bfseries 118.3 +- 7.9  & \bfseries 100\unit{\percent} & $\symbf{36.8 \pm 14.0}$ &  80\unit{\percent} \\
        \bottomrule
    \end{tabular}
\end{table}

\end{document}

Using \symbf gets the bf math font, but breaks the alignment. Could anyone please help? Thanks in advance!

3

1 Answer 1

2

Let me extend my comment to answer:

  • Something like this?

enter image description here

  • In real document you can remove red color, here is just for emphasis bold numbers in table.
  • Table use talltlbr of tabularray package. It enables zo write table notes below table.
  • In table is used siunitx syntax separate-uncertainty
  • Columns are in mode=text
\documentclass[12pt,a4paper,oneside]{memoir}

\usepackage{babel}  % Language hyphenation and typographical rules
\usepackage{csquotes}  % Context sensitive quotation facilities
\usepackage{microtype}  % Slightly tweak font spacing for aesthetics
\usepackage[warnings-off={mathtools-colon}]{unicode-math}
\setmainfont{EBGaramond-Regular}
\setmathfont{STIX Two Math}

\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx, varwidth}
    \SetTblrStyle{note}{font=\footnotesize}

\usepackage{etoolbox}
\newrobustcmd\B{\DeclareFontSeriesDefault[rm]{bf}{b}%
                \bfseries\color{red}}

\begin{document}
    \begin{table}
\sisetup{table-alignment-mode = format,
         table-number-alignment = center,
         detect-weight, % <--
         mode=text,     % <--
         separate-uncertainty
        }
    \centering
\begin{talltblr}[
caption = {Reserving space in \texttt{S} columns.},
  label = {tab:S:format},
note{\S}    = {some texplanationon},
note{\dag}  = {some texplanationon},
note{\ddag} = {some texplanationon}
                ]{colspec = {l 
                            Q[c, si={table-format=3.1(3)}]
                            Q[c, si={table-format=2.0}]
                            Q[c, si={table-format=2.1(3)}]
                            Q[c, si={table-format=3.0{\,\%}}]
                            },
                 cell{3-Z}{5} = {appto= {\,\%} },
                 row{1,2} = {guard}
                 }
    \toprule
        &   \SetCell[c=2]{c}    Point - mass
            &  &   \SetCell[c=2]{c}    Pendulum
                     &                  \\
        \cmidrule[lr]{2-3}
        \cmidrule[l]{4-5}
        &   Cost $(\mu \pm \sigma)$
            &   Succ.\TblrNote{\dag}
                &   Cost $(\mu \pm \sigma)$
                    &   Succ.\TblrNote{\ddag}   \\
    \midrule
mppi\TblrNote{\S}
        & {{{--}}}  
            & {{{--}}}  
                & 30.8(12.6)  
                    & 100           \\
disco   & 250.8(29.9)
            & 20
                & 61.3(40.0)
                    &  70           \\
svmpc   & 191.7(56.5)
            & 25
                & 44.5(17.9)
                    &  70           \\
dust    &\B 118.3(1)%(7.9)
            &\B 100
                &\B 36.8
                    &    80         \\
    \bottomrule
\end{talltblr}
    \end{table}
\end{document}
4
  • Fantastic, is it possible to meet the output by using dcolumn.sty, just a curiosity, I'm asking
    – MadyYuvi
    Mar 28, 2023 at 15:34
  • 1
    @MadyYuvi, I never tried but I don't see why it wouldn't work.
    – Zarko
    Mar 28, 2023 at 17:16
  • @Zarko, thanks for the reply, specially the addition of the table notes. But it is still not quite right. If you notice, the numbers are all being typeset on the main font (Garamond) and I'm trying to get them to use the maths font (STIX Two). The difference is more visible if you use \setmainfont{EBGaramond-Regular}[Numbers={OldStyle}]. If I remove mode=text from the \sisetup call, the font is correct, but \B doesn't change the font weight just the colour. Mar 29, 2023 at 5:15
  • @MadyYuvi, mode text is essential to have equal width of boldface and nobold faves fonts,, as you discover. Sory, but I'm not experts fo fonts eidher :-(
    – Zarko
    Mar 29, 2023 at 5:38

You must log in to answer this question.

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