Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
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 at 8:45
2  
Welcome to TeX.SX! –  Heiko Oberdiek Apr 9 at 9:08
3  
Should you not use \approx? –  Raphael Apr 9 at 13:12

3 Answers 3

up vote 6 down vote accepted

You could define

\newcommand{\appr}{{\mathord{\sim}}}

as per the answer you linked to; with double curly braces this is even usable in \SI like so

\SI{\appr 200}{\kelvin}

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

\documentclass{minimal}
\usepackage{siunitx}
\newcommand{\appr}{{\mathord{\sim}}}
\begin{document}
The temperature is \SI{\appr 200}{\kelvin}.

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

enter image description here

share|improve this answer
    
Use \approx, instead of define \appr. Also, the 2nd example looks like a big hack to me. –  jmc Apr 9 at 13:27
    
@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 at 13:36

~ 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

share|improve this answer
2  
You could add one sentence, why this is correct. The but stands so alone there. –  Johannes_B Apr 9 at 9:12
    
@Johannes_B OK, I added the reason. Thanks :) –  Harish Kumar Apr 9 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 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 Brunner Apr 9 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. –  Harish Kumar Apr 9 at 13:47

Like Raphael said in the comments:

\documentclass{minimal}
\usepackage{siunitx}
\begin{document}
The temperature is $\approx \SI{200}{\kelvin}.
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.