# How to write “is distributed as” under a certain hypothesis?

I'd need a special symbol used in statistics.

What I need is a tilde with something written upon it.

I can get the tilde by using \sim, but I need to add a superscript over it (H_0). If I use \sim^{H_0}, I get a tilde with H_0 over it and on the right, not simply upon it.

-
You might be interested in this question. – Thorsten Donig Feb 3 '12 at 22:07

The following minimal example provides two possibilities: \distas{<stuff>} and \distras{<stuff>}. The former uses amsmath's \overset{<top>}{<bottom>} which sets <top> over top of <bottom>. The latter uses a resized version of <bottom> in case <top> is wider than <bottom>. In fact, it stretches <bottom> to 6pt wider than <top> (3pt on either side). In both instances, <bottom> is fixed to \sim and the symbol is spaced as a binary operator via \mathbin.

\documentclass{article}
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\makeatletter
\newcommand{\distas}[1]{\mathbin{\overset{#1}{\kern\z@\sim}}}%
\newsavebox{\mybox}\newsavebox{\mysim}
\newcommand{\distras}[1]{%
\savebox{\mybox}{\hbox{\kern3pt$\scriptstyle#1$\kern3pt}}%
\savebox{\mysim}{\hbox{$\sim$}}%
\mathbin{\overset{#1}{\kern\z@\resizebox{\wd\mybox}{\ht\mysim}{$\sim$}}}%
}
\makeatother
\begin{document}

$X\distas{H_0}Y \quad X\distras{H_0}Y$
\end{document}

-
Thank you both Werner and Thorsten Donig! Your answers were very useful. I've solved by using: \overset{H_0}{\sim} – Luigi Feb 3 '12 at 22:12