4

I am trying to make table using siunitx and want to align the values by the decimal dots, but i got something like this instead:

enter image description here

code:

\begin{table}[!htb]
\centering
\sisetup{
  table-align-uncertainty=true,
  separate-uncertainty=true,
  output-exponent-marker = \text{e}
}
%% local redefinitions
\renewrobustcmd{\bfseries}{\fontseries{b}\selectfont}
\renewrobustcmd{\boldmath}{}

\begin{tabular}{
  l
  l
  l
  >{\color{blue}}S[table-format=3.4,detect-weight,mode=text,parse-numbers = true]
  @{${}\color{blue}\pm{}$}
  >{\color{blue}}S[table-format=2.4,detect-weight,mode=text,parse-numbers = true]
}
\toprule
{Test Problem}& {Budget}  & {Method}    & \multicolumn{2}{c}{\color{blue}Score}   \\
\midrule
Funct1        & 100    & Met1   & \bfseries\num{2.1854e+5} & \num{4.8133e+2}            \\ 
              & 100    & Met2   & \num{2.1972e+5} & \num{4.1228e+2}            \\ 
              & 250    & Met3   & \num{2.2152e+5} & \bfseries\num{4.6356e+1}             \\ \hline
Funct2        & 100    & Met1   & \bfseries 4.2191      & 0.0292            \\ 
              & 100    & Met2   & 4.4211      & \bfseries 0.0015              \\ 
              & 100    & Met3   & 4.3278      & 0.0074              \\ 
\bottomrule
\end{tabular}
\end{table}

when I am not using exponent it works perfectly even with \bfseries, is there something missing here?

2 Answers 2

3

With libertinus font and siunitx version 3:

\documentclass[border=3.141592, preview]{standalone}

\usepackage[semibold]{libertine}
\usepackage{libertinust1math}

\usepackage{xcolor}
\usepackage{booktabs}
\usepackage{siunitx}

\usepackage{etoolbox}
\newrobustcmd\B{\DeclareFontSeriesDefault[rm]{bf}{b}\bfseries}
\newcommand\mcc[1]{\multicolumn{1}{c}{#1}}

\begin{document}
    \begin{table}[htb]
\sisetup{
  text-series-to-math,
  output-exponent-marker = \text{e},
  table-format=1.4e1
}
\begin{tabular}{
  l
  l
  l
  >{\color{blue}}S
  @{\,\color{blue}$\pm$\,}
  >{\color{blue}}S
}
\toprule
Test Problem    
        & Budget    & Method    & \multicolumn{2}{c}{\textcolor{blue}{Score}}  \\
\midrule
Funct1  & 100       & Met1      &\B 2.1854e+5   & 4.8133e+2     \\
        & 100       & Met2      &   2.1972e+5   & 4.1228e+2     \\
        & 250       & Met3      &   2.2152e+5   &\B 4.6356e+1   \\ 
    \midrule
Funct2  & 100       & Met1      &\B 4.2191      & 0.0292        \\
        & 100       & Met2      &   4.4211      &\B 0.0015      \\
        & 100       & Met3      &   4.3278      & 0.0074        \\
    \bottomrule
\end{tabular}
    \end{table}
\end{document}

enter image description here

Addendum: A possible solution for "default" font family:

\documentclass[border=3.141592, preview]{standalone}

\usepackage{xcolor}
\usepackage{booktabs}
\usepackage{siunitx} % version v3.0.30

\usepackage{etoolbox}
\newrobustcmd\B{\DeclareFontSeriesDefault[rm]{bf}{b}\bfseries}
\newcommand\mcc[1]{\multicolumn{1}{c}{#1}}

\begin{document}
    \begin{table}[htb]
    \centering
\sisetup{detect-weight, % <--
         mode=text,     % <--
         output-exponent-marker = \text{e},
         table-format=1.4e1
}
\begin{tabular}{
  l
  l
  l
  >{\color{blue}}S
  @{\,\color{blue}$\pm$\,}
  >{\color{blue}}S
}
%%%% table body is the same as before
    \end{table}
\end{document}

enter image description here

2
  • is it possible to use default font for this? Commented Sep 23, 2021 at 15:28
  • @jajamaharaja, see addendum to answer.
    – Zarko
    Commented Sep 24, 2021 at 8:45
4

For siunitx version 3 and Computer Modern, I devised the following method:

\documentclass{article}
\usepackage{siunitx,booktabs}

% this is only necessary for Computer Modern
\DeclareMathVersion{tablebold}
\SetSymbolFont{operators}{tablebold}{OT1}{cmr} {b}{n}
\SetSymbolFont{letters}  {tablebold}{OML}{cmm} {b}{it}
\SetSymbolFont{symbols}  {tablebold}{OMS}{cmsy}{b}{n}
\sisetup{series-version-mapping/b = tablebold}
%%%

\begin{document}

\begin{table}[!htb]
\centering
%% local definition
\newcommand{\B}{\fontseries{b}\selectfont}

\sisetup{
  table-align-uncertainty=true,
  separate-uncertainty=true,
  output-exponent-marker = \text{e}
}

\begin{tabular}{
  @{}
  l
  S[table-format=3.0]
  l
  >{\color{blue}}S[table-format=1.4e1,detect-weight]
  @{${}\color{blue}\pm{}$}
  >{\color{blue}}S[table-format=1.4e1,detect-weight]
  @{}
}
\toprule
Test Problem & {Budget}  & Method    & \multicolumn{2}{c}{\color{blue}Score}   \\
\midrule
Funct1 & 100 & Met1 & \B 2.1854e+5 &    4.8133e+2 \\ 
       & 100 & Met2 & \B 2.1972e+5 &    4.1228e+2 \\ 
       & 250 & Met3 & \B 2.2152e+5 & \B 4.6356e+1 \\
\midrule
Funct2 & 100 & Met1 & \B 4.2191    &    0.0292    \\ 
       & 100 & Met2 &    4.4211    & \B 0.0015    \\ 
       & 100 & Met3 &    4.3278    &    0.0074    \\ 
\bottomrule
\end{tabular}
\end{table}

\end{document}

enter image description here

6
  • Clever approach: I might add it to the manual :)
    – Joseph Wright
    Commented Sep 23, 2021 at 9:13
  • @JosephWright There should also be an interface to set series-version-mapping; as far as I can see, there isn't one.
    – egreg
    Commented Sep 23, 2021 at 9:27
  • \sisetup{series-version-mapping/b = tablebold}
    – Joseph Wright
    Commented Sep 23, 2021 at 9:30
  • @JosephWright OK, that also might go in the manual.
    – egreg
    Commented Sep 23, 2021 at 9:47
  • got this error using overleaf LaTeX3 Error: The key 'siunitx/series-version-mapping/b' is unknown and is Commented Sep 23, 2021 at 15:27

You must log in to answer this question.

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