与包含数字结果的表格一样,我希望使用 标记一些值\textbf
(通常是获得的最佳结果)。当我尝试将S
提供的列类型siunitx
与结合使用时\textbf
,我会丢失小数分隔符对齐。已给出解决方案五年前,我试过了,但是不起作用:
\documentclass{article}
\usepackage{array,siunitx,booktabs,tabularx}
\robustify\bfseries
\sisetup{table-parse-only,detect-weight=true,detect-inline-weight=text}
\newcommand{\tbnum}[1]{\multicolumn{1}{c}{\bfseries \num{#1}}}
\begin{document}
\begin{tabularx}{\textwidth}{llXS}\toprule
A&B&C&\multicolumn{1}{c}{Numbers}\\\midrule
bla&bla&bla&0.535\\
bla&bla&bla&0.535\\
bla&bla&bla&0.535\\\midrule
bla&bla&bla&\tbnum{1322.0}\\\bottomrule
\end{tabularx}
\end{document}
我究竟做错了什么?
答案1
\documentclass{article}
\usepackage{array,siunitx,booktabs,tabularx}
\usepackage{etoolbox}
\robustify\bfseries
\sisetup{detect-weight=true,detect-inline-weight=text}
%\newcommand{\tbnum}[1]{\multicolumn{1}{c}{\bfseries \num{#1}}}
\begin{document}
\begin{tabularx}{\textwidth}{llXS}\toprule
A&B&C&\multicolumn{1}{c}{Numbers}\\\midrule
bla&bla&bla&0.535\\
bla&bla&bla&0.535\\
bla&bla&bla&0.535\\\midrule
bla&bla&bla&\bfseries 1322.0\\\bottomrule
\end{tabularx}
\end{document}
答案2
我将为单元格的内容定义强大的命令,S
使其加粗:
\documentclass{article}
\usepackage{booktabs,tabularx}
\usepackage{siunitx}
\usepackage{etoolbox}
\newrobustcmd\B{\DeclareFontSeriesDefault[rm]{bf}{b}\bfseries} % <--
\begin{document}
\begin{tabularx}{\textwidth}{l l X S[detect-weight, % <--
mode=text, % <--
table-format=4.1]
}
\toprule
A & B & C & {Numbers} \\
\midrule
bla & bla & bla & 0.535\\
bla & bla & bla & 0.535\\
bla & bla & bla & 0.535\\
\midrule
bla & bla & bla &\B 1322.0 \\
\bottomrule
\end{tabularx}
\end{document}