15

This question is similar to this one, only that I'm using the siunitx package:

\documentclass{minimal}
\usepackage{siunitx}
\begin{document}
The temperature is \SI{\sim 200}{\kelvin}. \\
The temperature is \SI{{\sim} 200}{\kelvin}. \\
The temperature is \SI{{\sim}200}{\kelvin}. \\
The temperature is $\sim$\SI{200}{\kelvin}.
\end{document}

The last line leads to the result I want. It is however not very elegant in my oppinion. Is there a way to tell the si package that I don't want a space before my value?

4
  • You could \newcommand{\unsim}{\mathord{\sim}} and use that in \SI{{\unsim}200}{\kelvin} or \SI{{\unsim} 200}{\kelvin}. Or even better \newcommand{\appr}{{\mathord{\sim}}} (the double curly braces are important) and \SI{\appr 200}{\kelvin}.
    – moewe
    Apr 9, 2014 at 8:45
  • 2
    Welcome to TeX.SX! Apr 9, 2014 at 9:08
  • 5
    Should you not use \approx?
    – Raphael
    Apr 9, 2014 at 13:12
  • In some fields, \sim, is used to mean "approximately". And I've only ever seen \approx mean "is approximately equal to" rather than merely "approximately", so T \approx 200 would be a correct use of it but The temperature is \approx 200 would not. (Please excuse lack of math mode and unit signifiers unnecessary to make this point.) Jul 8, 2021 at 19:41

4 Answers 4

18

Since version 2.1 siunitx supports so called comparators such as <, =, > and also \approx and \sim. In version 2.6 the spacing for these was fixed such that

\SI{\sim 200}{\kelvin}

now gives exactly what you want. See also input-comparators on p. 21 of the siunitx documentation.

MWE: compare this solution (first line) to your desired output (second line)

\documentclass{article}
\usepackage{siunitx}
\begin{document}
The temperature is \SI{\sim 200}{\kelvin}.

The temperature is $\sim$\SI{200}{\kelvin}.
\end{document}

enter image description here

4
  • Use \approx, instead of define \appr. Also, the 2nd example looks like a big hack to me.
    – jmc
    Apr 9, 2014 at 13:27
  • 2
    @jmc I would have liked to use \approx, but that macro is already defined and yields ≈. (Whether one should use the ∼ or ≈ symbol here is an entirely different matter.) The second example is just to compare my solution the OP's preferred output.
    – moewe
    Apr 9, 2014 at 13:36
  • That gives me an error: ! Missing } inserted. It's non fatal, but requires me to click enter to continue....
    – TheChymera
    Nov 1, 2016 at 21:19
  • 1
    @TheChymera Ah yes, thanks for the heads-up. siunitx has drastically improves support for \sim and friends since I wrote this. It is now enough to do \SI{\sim 200}{\kelvin}. You should never ignore an error by pressing enter even if the result seems all right (but of course you knew that, otherwise you wouldn't have commented).
    – moewe
    Nov 2, 2016 at 8:27
6

~ is a relational symbol and should be used such. Further you can use \SI macro inside the math mode. Hence, the correct way is

\documentclass{minimal}
\usepackage[detect-all]{siunitx}    
\begin{document}
The temperature is $\sim\SI{200}{\kelvin}$.
\end{document}

enter image description here

10
  • 2
    You could add one sentence, why this is correct. The but stands so alone there.
    – Johannes_B
    Apr 9, 2014 at 9:12
  • @Johannes_B OK, I added the reason. Thanks :)
    – user11232
    Apr 9, 2014 at 9:43
  • It's the same here for ~ as for <: You always write $x$ is in modulus $<1$ and not ... in modulus $<$1.
    – yo'
    Apr 9, 2014 at 9:51
  • Just to clarify: do you mean this solely in a programming context? Because I was referring mainly to the typography of my text and especially with single digit numbers the rather huge distance to the ~ looks a bit strange to me. In the scientific literature connected to my work I've found both notations so I don't know if there is a "right" one.
    – Lukas
    Apr 9, 2014 at 10:12
  • 2
    @Hans-PeterE.Kristiansen In physics, it is ~ 200K and not ~200K. This appears to be physics related. In the question, the OP doesn't want ~ to be relational but unary (I know) but that, according to me, is not correct. Hope I am clear now.
    – user11232
    Apr 9, 2014 at 13:47
1

The result of

Lichtgeschwindigkeit (\SI{\sim300000}{\kilo\meter\per\second}) Richtung Erde

is

enter image description here

without space between

0

Like Raphael said in the comments:

\documentclass{minimal}
\usepackage{siunitx}
\begin{document}
The temperature is $\approx \SI{200}{\kelvin}$.
\end{document}

You must log in to answer this question.

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