5

Can the space between the value and the unit be added automatically, when units are written using the SIunits package?

The package gives the following two options to add units:

$500\kelvin$
$\unit{500}{\kelvin}$

enter image description here

Only the latter adds seperation between value and unit. Adding the \unit{...}{...} parameter is too cumbersome and doesn't give any ease of use compared to the manual \;\mathrm{...} method.

Using the former notation to avoid this, the space can be added manually with \; of course, 500\;\kelvin, but I am now looking for the possibility of never having to add anything but the unit.

I have looked into the siunitx package as well, which only replaces the \unit{...}{...} with \SI{...}{...} (and apparently makes it mandatory!). This therefore gives no help.

Is it possible to automatically/generally add a \; before every single unit (and unit group) in the document?

2
  • 3
    The package information says “Note that the pack­age is now su­per­seded by siu­nitx; siu­nits has main­te­nance-only sup­port, now.” So that’s your answer: use siunitx, not SIunits. Commented Apr 11, 2017 at 12:41
  • 3
    @KonradRudolph Indeed: I'm at least formally in charge of SIunits. The statement means that there will be no features added, but here we are talking about usage of existing abilities (thought I'd still go with siunitx).
    – Joseph Wright
    Commented Apr 11, 2017 at 13:06

2 Answers 2

11

One could achieve this in SIunits by patching an appropriate internal

\documentclass{article}
\usepackage{SIunits}
\usepackage{xpatch}
\makeatletter
\xpretocmd\SI@fstyle{\;}{}{}
\makeatother
\begin{document}
$500\;\mathrm{K}$

$500\kelvin$

\end{document}

You can also do this in siunitx by activating 'free standing' units and 'pre-spacing'

\documentclass{article}
\usepackage{siunitx}
\sisetup{free-standing-units, space-before-unit, number-unit-product = \;}
\begin{document}

$500\;\mathrm{K}$

$500\kelvin$

\end{document}

(Using \qty is recommended as there are outcomes that require a more structured mark-up, but one design aim has always been to support a range of input forms.)


For these approaches to work you have to have the unit as a single command: chaining things together such as \volt\per\kelvin won't work as there is no way to 'know' what marks the end of the unit. For siunitx we can declare a new unit which will then only add a space at the start

\documentclass{article}
\usepackage{siunitx}
\sisetup{free-standing-units, space-before-unit, number-unit-product = \;}
\DeclareSIUnit{\voltperkelvin}{\volt\per\kelvin}
\begin{document}

$500\;\mathrm{V}\,\mathrm{K}^{-1}$

$500\voltperkelvin$

\end{document}

(The need to define units 'up front' for 'pre-spacing' to work is one reason the siunitx documentation is primarily focussed on logic mark up.)

This is much harder to achieve with SIunits as the unit commands are not context-sensitive. One might add appropriate switching but this becomes a significant change in the way the code works: probably crosses into 'development' (which as the SIunits documentation says is now done in siunitx.)

0
3

You can control the spacing with number-unit-product, either as package option, or with \sisetup or locally only within \SI[number-unit-product=...]{500}{\kelvin}, but you should think about this whether this is really needed

(Of course, \quad is exaggerated!)

\documentclass{article}

\usepackage[number-unit-product=\quad]{siunitx}


\begin{document}

\SI{500}{\kelvin}
% Local change
\SI[number-unit-product=\,\,]{1000}{\meter}

\end{document}

enter image description here

1
  • @Steeven: I understood that but I don't recommend it ;-) I had a similar approach in all of my worksheets etc. for my students and switched (with some help of \sed etc. to \SI usage.
    – user31729
    Commented Apr 11, 2017 at 12:18

You must log in to answer this question.

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