Jak zrobić wpisy siunitx w tabeli pogrubioną czcionką?
Nov 23 2020
Korzystam z siunitx
pakietu w środowisku tabelarycznym. Jak mogę pogrubić wpisy? Oto 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}

Odpowiedzi
2 Zarko Nov 23 2020 at 01:19
Całkiem podobny do odpowiedzi @leandriss, z nieco krótszym kodem i równą szerokością pogrubionych i normalnych cyfr na twarzy:
\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}

Edycja: W pierwszej wersji była definicja \B
opcji utraconej \bfseries
. Teraz jest dodawany i pokazuje poprawioną tabelę.
4 leandriis Nov 23 2020 at 01:00
W porównaniu do oryginalnego kodu, dodałem decect-weight
do \sisetup
, używane bfseries
zamiast \textbf
i umieszczone \usepackage{etoolbox}\robustify\bfseries
w preambule dokumentu. Na koniec zastosowałem również odpowiednie table-format
opcje dla obu S
typów kolumn.

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