0

I need to redefine the \percent unit in siunitx so that it reads "percent" in running text but remains as "%" in tables and equations. I assume there must be an option for this, but I looked into the package documentation and couldn't find any.

3
  • Hmmm... I am not sure that it is possible to say if you are in a table or not. So maybe math mode - no math mode is possible, but the other one is difficult.
    – Rmano
    Commented May 25, 2020 at 16:59
  • I once defined a \light command as \newcommand{\light}[1][per-mode = symbol-or-fraction]{\SI[#1]{299792458}{\meter\per\second}}, which chooses whether to write the m/s units as an inline or a displayed fraction according to context, and I thought something similar might be possible here.
    – nemarona
    Commented May 25, 2020 at 17:20
  • That command is simply a command with an optional argument and a default... so that \light use the indicated per-mode by default, and you can override it. No automatic switching.
    – Rmano
    Commented May 25, 2020 at 17:34

1 Answer 1

1

I do not know if there is a method to decide if you are in a table or not. What does exist is a way to check if your are in math mode or not; you can do something like this:

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

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .