표 굵은 체로 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\bfseriestable-formatS

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