表の太字にsiunitxエントリを作成するにはどうすればよいですか?
Nov 23 2020
siunitx
表形式の環境でパッケージを使用しています。エントリを太字にするにはどうすればよいですか?これがMWEです。
\documentclass[oneside,11pt]{book}
\usepackage[
expansion = false ,
tracking = smallcaps ,
letterspace = 40 ,
]{microtype}
\usepackage{booktabs}
\usepackage{siunitx}
\sisetup{%
detect-family, detect-shape,
product-units = power,
list-final-separator = {, and },
retain-explicit-plus,
input-comparators = {<=>\approx\ge\geq\gg\le\leq\ll\sim\lesssim\gtrsim}
}
\DeclareSIUnit[number-unit-product = ]\percent{\char`\%}
\begin{document}
\begin{table}[!h]
\centering
\begin{tabular}{lll}
\toprule
A & {B} & {C}\\
\midrule
\textbf{Bob} & \textbf{\SI{75}{\percent}} & \textbf{-11.11}\\
Carla & \SI{75}{\percent} & 2.22\\
Dale & \SI{75}{\percent} & -3.33\\
Ena & \SI{75}{\percent} & 4.44\\
\bottomrule
\end{tabular}
\caption{Caption 1}
\end{table}
\begin{table}[!h]
\centering
\begin{tabular}{lSS}
\toprule
A & {B} & {C}\\
\midrule
\textbf{Bob} & \textbf{\SI{75}{\percent}} & \textbf{-11.11}\\
Carla & \SI{75}{\percent} & 2.22\\
Dale & \SI{75}{\percent} & -3.33\\
Ena & \SI{75}{\percent} & 4.44\\
\bottomrule
\end{tabular}
\caption{Caption 2}
\end{table}
\begin{table}[!h]
\centering
\begin{tabular}{lSS}
\toprule
A & {B} & {C}\\
\midrule
Bob & \SI{75}{\percent} & -11.11\\
Carla & \SI{75}{\percent} & 2.22\\
Dale & \SI{75}{\percent} & -3.33\\
Ena & \SI{75}{\percent} & 4.44\\
\bottomrule
\end{tabular}
\caption{Caption 3}
\end{table}
\end{document}

回答
2 Zarko Nov 23 2020 at 01:19
@leandrissの回答と非常によく似ていますが、コードがわずかに短く、太字と通常の顔の数字の幅が同じです。
\documentclass[oneside,11pt]{book}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{etoolbox}
\newrobustcmd\B{\DeclareFontSeriesDefault[rm]{bf}{b}\bfseries}
\newcommand\mcc[1]{\multicolumn{1}{c}{#1}}
\begin{document}
\begin{table}[!h]
\centering
\sisetup{detect-weight,
mode=text,
table-format=2.0
}
\begin{tabular}{lS[table-space-text-post=\,\%]<{\,\%}
S[table-format=-2.2]}
\toprule
A & \mcc{B} & \mcc{C}\\
\midrule
Bob & 75 &\B -11.11\\
Carla & 75 & 2.22\\
Dale & 75 & -3.33\\
Ena & 75 & 4.44\\
\bottomrule
\end{tabular}
\caption{Caption 3}
\label{tab:boldsiunitx}
\end{table}
\end{document}

編集:最初のバージョンでは、\B
失われたオプションの定義にありました\bfseries
。これで追加され、修正されたテーブルが表示されます。
4 leandriis Nov 23 2020 at 01:00
元のコードと比較して、ドキュメントのプリアンブルに追加decect-weight
し\sisetup
、bfseries
代わりに使用\textbf
して配置し\usepackage{etoolbox}\robustify\bfseries
ました。最後に、table-format
両方のS
タイプの列に適切なオプションも使用しました。

\documentclass[oneside,11pt]{book}
\usepackage[
expansion = false ,
tracking = smallcaps ,
letterspace = 40 ,
]{microtype}
\usepackage{booktabs}
\usepackage{siunitx}
\sisetup{%
detect-family, detect-shape,
product-units = power,
list-final-separator = {, and },
retain-explicit-plus,
input-comparators = {<=>\approx\ge\geq\gg\le\leq\ll\sim\lesssim\gtrsim},
detect-weight
}
\DeclareSIUnit[number-unit-product = ]\percent{\char`\%}
\usepackage{etoolbox}
\robustify\bfseries
\begin{document}
\begin{table}[!h]
\centering
\begin{tabular}{lS[table-format=2,table-space-text-post=\%]S[table-format=-2.2]}
\toprule
A & {B} & {C}\\
\midrule
Bob & \SI{75}{\percent} & \bfseries -11.11\\
Carla & \SI{75}{\percent} & 2.22\\
Dale & \SI{75}{\percent} & -3.33\\
Ena & \SI{75}{\percent} & 4.44\\
\bottomrule
\end{tabular}
\caption{Caption 3}
\end{table}
\end{document}