
我需要重新定义\percent
单位,siunitx
使其在运行文本中显示为“百分比”,但在表格和方程式中仍显示为“%”。我认为一定有一个选项,但我查看了软件包文档,没有找到任何选项。
答案1
我不知道是否有方法可以确定您是否在表中。什么做exist 是一种检查您是否处于数学模式的方法;您可以执行以下操作:
\documentclass{article}
\usepackage{siunitx}
\DeclareSIUnit{\textpercent}{percent}
\newcommand{\autopercent}{\ifmmode\,\si{\percent}\else\si{\textpercent}\fi}
\begin{document}
This is in text: 12~\autopercent; and you have to use \verb|{}| after the
command as in 5~\autopercent{} if you have a space after. In equation:
\[
A = 14\autopercent
\]
\end{document}