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?

Lukas
  • 579
  • 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 09 '14 at 08:45
  • 2
    Welcome to TeX.SX! – Heiko Oberdiek Apr 09 '14 at 09:08
  • 5
    Should you not use \approx? – Raphael Apr 09 '14 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.) – Michael Hoffman Jul 08 '21 at 19:41

4 Answers4

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

moewe
  • 175,683
  • Use \approx, instead of define \appr. Also, the 2nd example looks like a big hack to me. – jmc Apr 09 '14 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 09 '14 at 13:36
  • That gives me an error: ! Missing } inserted. It's non fatal, but requires me to click enter to continue.... – TheChymera Nov 01 '16 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 02 '16 at 08: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

  • 2
    You could add one sentence, why this is correct. The but stands so alone there. – Johannes_B Apr 09 '14 at 09:12
  • @Johannes_B OK, I added the reason. Thanks :) –  Apr 09 '14 at 09:43
  • It's the same here for ~ as for <: You always write $x$ is in modulus $<1$ and not ... in modulus $<$1. – yo' Apr 09 '14 at 09: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 09 '14 at 10:12
  • @LukasBrunner No, this is a math thing. Think of the difference between minus as a unary and binary operator, for example 3 - -2=5 – Johannes_B Apr 09 '14 at 10:33
  • No. In this question ~ is NOT a relational symbol, it is an unary operator. Look at the question, that OP links to. – hpekristiansen Apr 09 '14 at 10:59
  • 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. –  Apr 09 '14 at 13:47
  • Ok - I see your point, but I(and wikipedia) do not agree. My question: http://tex.stackexchange.com/questions/55701/how-do-i-write-sim-approximately-with-the-correct-spacing and wikipedia: http://en.wikipedia.org/wiki/Tilde explains the two different uses. – hpekristiansen Apr 09 '14 at 16:26
  • @Harish Kumar: Good luck with that delusion. – hpekristiansen Apr 10 '14 at 05:08
  • Actually, I thought in physics, we should write ~ 200 K ? – K.-Michael Aye Jan 24 '18 at 01:15
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}
moewe
  • 175,683
jmc
  • 1,660