\num
因此,我尝试将命令中表达式得出的数字加粗:
\documentclass[12pt]{article}
\usepackage{xfp}
\usepackage{siunitx}
\sisetup{group-separator = {,}, group-minimum-digits = 4}
\begin{document}
\textbf{\$36,717} $-$ \textbf{\$25,640} = \$$\mathbf{\num[bracket-negative-numbers]{\fpeval{36717 - 25640}}}$
\textbf{\$36,717} $-$ \textbf{\$25,640} = \$$\mathbf{\num[bracket-negative-numbers, evaluate-expression]{36717 - 25640}}$
\textbf{\$36,717} $-$ \textbf{\$25,640} = \$$\boldmath{\num[bracket-negative-numbers]{\fpeval{36717 - 25640}}}$
\textbf{\$36,717} $-$ \textbf{\$25,640} = \$$\boldmath{\num[bracket-negative-numbers, evaluate-expression]{36717 - 25640}}$
Desired: \textbf{\$11,077}
\end{document}
输出:
如图所示,两者都不\mathbf
执行\boldmath
任何操作。另一方面,如果我将两者中的任何一个放在命令的输入部分(即括号部分)\num
,则会出现错误。如何使表达式中的答案加粗?
\num[evaluate-expression]{...}
此外,如果有人能解释一下和之间的区别的\fpeval{...}
话,那该怎么办?
答案1
对于文本模式打印,您需要设置reset-text-series = false
。设置文本打印并制作几个自定义命令以获得更结构化的输入,您可以使用
\documentclass[12pt]{article}
\usepackage{siunitx}
\sisetup
{
% Unrelated to the bold issue,
% but to get the desired output format
group-separator = {,},
group-minimum-digits = 4,
bracket-negative-numbers,
% Automatically 'do maths'
evaluate-expression ,
% Use text mode for printing numbers,
% and allow them to be bold
mode = text ,
reset-text-series = false
}
% Make a couple of custom commands for the document
\NewDocumentCommand\dollarvalue{m}{\text{\$}\num{#1}}
\NewDocumentCommand\boldvalue{m}{\text{\textbf{\dollarvalue{#1}}}}
\begin{document}
$\boldvalue{36717} - \boldvalue{25640} = \boldvalue{36717 - 25640}$
\end{document}
或者,如果您想在数学模式下打印,但又要\boldmath
应用到 打印的值siunitx
,那么您需要reset-math-version = false
。再次让事情更有条理,这次不使用单独的命令来显示粗体值:
\documentclass[12pt]{article}
\usepackage{siunitx}
\sisetup
{
% Unrelated to the bold issue,
% but to get the desired output format
group-separator = {,},
group-minimum-digits = 4,
bracket-negative-numbers,
% Automatically 'do maths'
evaluate-expression ,
% Allow math values to be bold
reset-math-version = false
}
% Make a ccustom command for the document
\NewDocumentCommand\dollarvalue{m}{\$\num{#1}}
\begin{document}
\boldmath
$\dollarvalue{36717} - \dollarvalue{25640} = \dollarvalue{36717 - 25640}$
\end{document}