我一直尝试使用 siunitx 将表格中的某些条目排版为粗体,以实现正确的对齐。
我尝试过在网上找到的许多其他答案,但我遇到的问题是,我希望以数学字体而不是主字体来呈现数字。
这是目前针对我的问题的最小示例代码:
%!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}
使用\symbf
会获取 bf 数学字体,但会破坏对齐。有人可以帮忙吗?提前谢谢!
答案1
让我扩展我的评论来回答:
- 像这样吗?
- 在实际文档中,您可以删除红色,这里只是为了强调表格中的粗体数字。
talltlbr
包的表格使用tabularray
。它允许在表格下方写入表格注释。- 表中使用的
siunitx
语法separate-uncertainty
- 列位于
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}