Comment faire des entrées siunitx dans un tableau en gras?
J'utilise le siunitx
package dans un environnement tabulaire. Comment puis-je mettre les entrées en gras? Voici un 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}

Réponses
Assez similaire à la réponse @leandriss, avec un code légèrement plus court et une largeur égale de caractères gras et de chiffres normaux:
\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}

Edit: Dans la première version était dans la définition de l' \B
option perdue \bfseries
. Maintenant est ajouté et montré le tableau corrigé.
Par rapport à votre code d' origine, j'ai ajouté decect-weight
à \sisetup
, utilisé au bfseries
lieu de \textbf
et placé \usepackage{etoolbox}\robustify\bfseries
dans le préambule du document. Enfin, j'ai également utilisé des table-format
options appropriées pour les deux S
colonnes de type.

\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}