TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I set the tilde (~) character correctly in LaTeX?

There’s a question discussing that on Stack Overflow, with a lot of answers. But dare I say it? They all suck:

  • \textasciitilde is too high,
  • \texttildelow is too low.
  • $\sim$ can be tweaked to look more or less acceptable: {\raise.17ex\hbox{$\scriptstyle\sim$}} – but even that is a hack and uses the wrong symbol.

The point is – the tilde character is definitely an existing glyph in any font I am tempted to use. How can I just access and typeset that character, please? Without resorting to some other, similar-looking glyph that first needs to be nudged into place using a cunning combination of font size and raised boxes?

There must be a possibility to access that glyph directly from the font definition.

To demonstrate, look at this screenshot which attempts simply to display a C++ destructor of a type T (~T):

tilde symbols

Compare this with the symbol we get in the browser: ~that’s what I want.

share|improve this question
up vote 30 down vote accepted

It all depends on what do you want this glyph to stand for.

If you want to use it in an url then add \usepackage{url} (or hyperref) to your preamble and then use \url{http://example.com/~user}.

If you want to use it inside a math formula as some kind of relation then use $a \sim b$.

According to the "Comprehensive Symbols List", to get a vertically centered ~ you can use \texttildelow in any font other than Computer Modern, txfonts, and pxfonts. For example the following does the trick for typesetting a C++ destructor


\texttildelow T
share|improve this answer
Yes, I should have excluded URIs and math mode from the question. But the \text… variants are definitely not using the correct symbol. – Konrad Rudolph Jul 27 '10 at 9:40
Can I ask again "In which context to you want the symbol to appear?" – Juan A. Navarro Jul 27 '10 at 10:00
@juan: well, in normal text. To give a concrete example, consider source code, e.g. when using a C++ destructor, ~T(). – Konrad Rudolph Jul 27 '10 at 10:37
Thanks. I see now that I need to ask a new question – because this solution still doesn’t work with XeTeX in conjunction with TrueType fonts. – Konrad Rudolph Jul 27 '10 at 13:54
Uh, scratch that. For TTF/OTF fonts, \char`~ works. – Konrad Rudolph Jul 27 '10 at 14:01

Here’s a list for completeness’ sake.

If you want to typeset a URL or file path, use the url (or hyperref) package with the appropriate command and be done with. Otherwise, there are three distinct cases:

  1. You are using the standard Computer Modern font, txfonts or pxfonts: use DocBucket’s workaround:

  2. You are using a T1 font via a package such as times: use texttildelow from the textcomp package (no workaround needed; in particular, do not load lmodern, otherwise this won’t work any longer).

  3. If you are using a TTF or OTF font via XeTeX or LuaTeX: Use \char`~ to insert a tilde.
share|improve this answer
+1 for XeLaTeX! – Sibbs Gambling May 28 '14 at 15:33
I'm using a font called iwona which I think is T1 and I can't get either \texttildelow or \char`~ to work. – gghuffer Apr 6 at 2:52

This is a bug in Computer Modern. \textasciitilde is the correct character and should be rendered vertically centred. To fix it, the best way is to use Latin Modern with T1 enconding, as in


\usepackage{lmodern} \usepackage[T1]{fontenc}

\begin{document} \textasciitilde T \end{document}

This also works with any font that I bothered to try, like mathpazo, times, berasans, inconsolata, etc.

EDIT: Rewrote answer in response to comment.

share|improve this answer
This is the correct answer. – Mk12 Aug 25 '12 at 18:07
Actually this doesn’t seem to work. An MWE, loading the article document class, lmodern and trying to typeset \textasciitilde{}T produces the wrong tilde (high up). – Konrad Rudolph Jul 8 '13 at 8:28
You're right. The problem is that I have never thought about using Latin Modern with legacy enconding. You must use \usepackage[T1]{fontenc} to have correct results. – Mateus Araújo Jul 30 '13 at 13:25

according to the Comprehensive LaTeX Symbol List, \texttildelow "produces a vertically centered “~” in most fonts but a baseline-oriented “~” in Computer Modern, txfonts, pxfonts, and various other fonts originating from the TEX world." So to produce a centered Tilde, one can use something like


(Taken from the symbol list source code. A different font might give a better result, depending on what the main font of your text is.)

share|improve this answer

None of the existing answers really do the trick for me. In particular,

  • switching to another font (e.g. {\fontfamily{ptm}\selectfont\texttildelow}) hurts my stickler's heart;
  • using $\sim$ doesn't look good, especially in bold typewriter;
  • I'd really like a macro that typesets a vertically centred tilde regardless of the font and encoding used.

Here is a table summarising the tests I ran (mostly on TeX fonts):

enter image description here

The \midtilde macro is my attempt at typesetting a vertically centred tilde, regardless of the font being used. I haven't tested it on any other font than those listed in the table. Please let me know (in the comments) if you find fonts for which \midtilde doesn't produce a vertically centred tilde.









  \fontfamily{#1}\selectfont\f@family         &
  \fontfamily{#1}\selectfont A\texttildelow a & 
  #2                                          &
  \fontfamily{#1}\selectfont A\midtilde a      \\

    \texttt{Font family} & A\texttt{\string\texttildelow} a & centred? & A\texttt{\string\midtilde} a \\

share|improve this answer
After \usepackage{newtxtext}, \midtilde sits far too low in either Roman or sans-serif text. I fixed this locally by adding t1ntxrx and t1ntxss to the longer of the two lists of font families. But perhaps this is better handled by reporting it as a bug against the newtxtext package? – Ben Liblit Oct 17 '14 at 23:06
It fails if you load cfr-lm. I think it is reasonable for cfr-lm to follow lmodern by default, so if you want this to be a general solution, I think the families defined by cfr-lm need to be accommodated in the same way as the other CM/LM variants. – cfr Feb 3 '15 at 1:50
Updating my first comment above, newtxtext 1.4 and later has switched to using TeXGyre Termes fonts, which put me back to seeing a \midtilde that sat far too low in either Roman or sans-serif text. I fixed this locally by adding t1ntxrj, t1qhv, and ts1qhv to the longer of the two lists of font families. – Ben Liblit Nov 19 '15 at 16:12

Every time I google the tilde problem, this question comes up. I cannot be the only one finding the link this way.

In that case, here's the simple fix (edit: for the Computer Modern font) that I cannot believe I have yet to see anywhere else. Note that most of the code below is a MWE; the fix itself is only two lines (one line if you already use textcomp)





\section{Unsatisfying fixes}

Using \verb+\texttildelow{}12+ (with the \texttt{textcomp} package) gives: 
My dog weighs \texttildelow{}12~kg.
Using \verb+\url{~12}+ (with the \texttt{url} package) gives:
My dog weighs \url{~12}~kg.
Using \verb+$\sim$12+  gives:
My dog weighs $\sim$12~kg.

\section{My fix}
In the preamble:
Using \verb+\textapprox{}12+ gives:
My dog weighs \textapprox{}12~kg.
That looks about right to me. If you want to change the height, it's easy to do so globally by tweaking the \texttt{0.5ex} value.
share|improve this answer
Actually, \texttildelow by itself should work just fine with T1, no “raisebox” needed, as long as you are not using the CM font (your solution works for CM though). If you are using a TTF font, then \char`~ should work. It’s not very clear but it’s written in a comment above. – Konrad Rudolph Jul 8 '13 at 7:06
Oh, I should have mentioned that I was specifically talking about CM. Do most people switch into a different font? Maybe it's because I'm new to LaTeX, but I still rather like CM so I'm currently writing with it. – DocBuckets Jul 8 '13 at 14:00
Well I cannot judge, I dislike the look of CM so I never use it. But my comment wasn’t meant as discouragement. This is actually a solid answer, in particular since the lmodern workaround, mentioned above, doesn’t work. – Konrad Rudolph Jul 8 '13 at 14:03

This problem was also driving me crazy for typesetting code in an lstlisting. I solved it with


Most of the other answers here either don't work in a listing, or require more gymnastics than I was ready to undertake.

share|improve this answer

I had the same difficulties. In my case, the context was indeed an URL but the existing suggestions didn't quite work as I expected and the \url{} command was reducing the size of the font (making the text weird compared to the rest of the paragraph).

Then, I found this suggestion that worked like a charm! :)

% [...]


% [...]
share|improve this answer

Your Answer


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.