我正在尝试使用 siunitx 制作表格,并希望按小数点对齐值,但我得到的却是这样的结果:
代码:
\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}
当我不使用指数时,它甚至可以完美地工作\bfseries
,这里缺少了什么吗?
答案1
使用libertinus
字体和siunitx
版本 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}
附录: “默认”字体系列的可能解决方案:
\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}
答案2
对于siunitx
版本 3 和 Computer Modern,我设计了以下方法:
\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}