how can I set an horizontal space before the units using the siunitx package in math mode?

I often use the \si[]{} command from the siunitx package in math mode to avoid formatting the units using \mathrm{} and superscripts, however when doing this there is no space displayed at all between the numbers and the units, it looks weird.

for example:

$$\mathrm{m}=1 \si{\kilo\gram}$$


I can overcome this in inline math mode doing this:

$$\mathrm{m}=1$$ \si{\kilo\gram}


But I can´t do this most math environments.

Note that there is a white space between units when you use two or more of them

$$\mathrm{k}=40$$ \si{\newton\per\meter}


I would like to add a white space between the numbers and the units similarly to the one between Newton and metre when using the \si[]{} command in math mode.

How can that be done?

MWE:

\documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{siunitx}
\begin{document}
Some math in inline mode $$\mathrm{m}=1$$ \si{\kilo\gram}, and some centered math:
$\mathrm{k}=40 \si{\newton\per\meter}$
\end{document}

• Why don't you use \SI{1}{\kilo\gram}? – Ulrike Fischer Apr 17 '18 at 7:32
• There is this example in the documentation \SI[mode=text]{1.23}{J.mol^{-1}.K^{-1}} and I still see the J very close to the 1.23, is that because of the mode=text option? – Paul Lara Apr 17 '18 at 7:39
• The space looks okay to me, but if you want a larger one it can be configured, see the documentation. – Ulrike Fischer Apr 17 '18 at 7:44
• @PaulLara - The outputs of \SI[mode=text]{1.23}{J.mol^{-1}.K^{-1}} and \SI{1.23}{J.mol^{-1}.K^{-1}} differ only if text-mode and math-mode numerals differ. (The user guide of the siunitx package uses oldstyle numerals in text mode.) The mode=text option does not influence the space between the numeric and units parts of \SI. Speaking for myself, I prefer the form \SI{1.23}{\joule\per\mole\per\kelvin}, both because I find it to be easier to parse and because its output can be reconfigured "on the fly", with options such as per-mode=symbol and per-mode=fraction. – Mico Apr 17 '18 at 8:29

Using your method of keeping the number and units separate, you would need to add the desired space explicitly. Using the \SI{}{} command, you can adjust this by changing the value of number-unit-product using \sisetup. See table 24 in the documentation.

\documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{siunitx}
\begin{document}
Some math in inline mode $$\mathrm{m}=\SI{1}{\kilo\gram}$$, and some centered math:
$\mathrm{k}=\SI{40}{\newton\per\meter}$

\sisetup{number-unit-product=\ }
Some math in inline mode $$\mathrm{m}=\SI{1}{\kilo\gram}$$, and some centered math:
$\mathrm{k}=\SI{40}{\newton\per\meter}$
\end{document}