siunitx icon indicating copy to clipboard operation
siunitx copied to clipboard

Option to add a space between preunit and number

Open wojciechbielecki opened this issue 7 years ago • 1 comments

There is no easy option to add a space (i.e. product sign) between the preunit and the number when using \SI{123}[preunit]{}.

The current workaround is to define a unit with a thin space at the end, like \DeclareSIUnit[]{\EURs}{\textsc{eur\,}}, but then it is useful only with \SI command, and not on its own in \si, as it will add extra space. This requires defining two units for the two purposes.

Example: screen shot 2018-03-03 at 21 20 48

Code:

\documentclass{article}
\usepackage[round-mode=places,round-integer-to-decimal]{siunitx}

% Using full spaces for demonstration
\DeclareSIUnit[]{\EURspace}{\textsc{eur\ }}
\DeclareSIUnit[]{\EUR}{\textsc{eur}}

\begin{document}
\verb|\EURspace| defined as \verb|\textsc{eur\ }|. \\
\verb|\EUR| defined as \verb|\textsc{eur}|. \\
Using \verb|\si{\EURspace}|: \si{\EURspace}. (bad) \\
Using \verb|\SI{123.00}[\EURspace]{}|: \SI{123}[\EURspace]{}. (ok) \\
Using \verb|\si{\EUR}|: \si{\EUR}. (ok) \\
Using \verb|\SI{123.00}[\EUR]{}|: \SI{123}[\EUR]{}. (bad) \\
\end{document}```

wojciechbielecki avatar Mar 03 '18 20:03 wojciechbielecki

Perhaps this could be solved by adding an option unit-number-product in parallel to existing number-unit-product.

I understand that the current behaviour may be expected when using currencies symbols (€, $, £), but with ISO codes, there should be a space.

Current solution seems to be:

\usepackage{xifthen,siunitx} % xifthen for \isempty
\DeclareSIUnit[]{\EURspace}{\textsc{eur\,}} % EUR with a thin space
\DeclareSIUnit[]{\EUR}{\textsc{eur}}
\newcommand{\eur}[1]{%
	\ifthenelse{\isempty{#1}}%
	{\si{\EUR}}%
	{\SI{#1}[\EURspace]{}}%
}

And then, using \eur{} for only the unit, or \eur{123} with a number.

wojciechbielecki avatar Mar 03 '18 20:03 wojciechbielecki

For v3 I dropped the pre-unit as it really wasn't a good idea. As such, I'm closing here.

josephwright avatar Jul 28 '23 06:07 josephwright