Just like \xrightarrow allows to decorate \rightarrow with text above and below, I would like to do exactly the same for \sim instead or \rightarrow

Is there an easy way to do it ?

PS : I can get a fixed length \sim via

$A \overset{x}{\underset{\mathclap{\varphi}}{\sim}} B$
  • Are you asking if it's possible to get an "extensible \sim" symbol, in analogy to extensible arrows such as those generated by \xrightarrow? Please advise.
    – Mico
    Sep 9, 2021 at 10:10
  • In your opinion, what should an extensible version of \sim look like? E.g., should it be a version of \sim that's stretched horizontally, or should it consist of several concatenated wavy wiggles, with each wavy wiggle consisting of an instance of \sim?
    – Mico
    Sep 9, 2021 at 10:26
  • 1
    Off-topic: \overset{x}{\underset{\mathclap{\varphi}}{\sim}} could be expressed more simply as \overunderset{x}{\varphi}{\sim}.
    – Mico
    Sep 9, 2021 at 10:27
  • yes, I was looking for an extensible sim, stretched horizontally
    – nicolas
    Sep 9, 2021 at 10:32
  • thanks for the tip !
    – nicolas
    Sep 9, 2021 at 10:36

1 Answer 1


The following code defines a user command named extoverset, which takes two mandatory arguments and acts like \overset, except that it stretches the width of the 2nd argument (say, \sim) to equal the width of the first argument. An optional third argument can be used to fine-tune the resulting widths.

Certainly not perfect -- but hopefully it's a (decent?) start.

enter image description here

\usepackage{amsmath}    % for '\overset' macro
\usepackage{calc}       % for '\widthof' macro
\usepackage{graphicx}   % for '\resizebox' macro

  \resizebox{#1+\widthof{\scriptsize #2}}{\height}{$#3$}}

\obeylines % just for this example
$A \overset{aa}{\sim} B$
$A \extoverset{$aa$}{\sim} B$
$A \extoverset[6pt]{long expression}{\sim} B$
$A \extoverset[8pt]{long expression}{=} B$
  • 1
    nice and simple ! perfect for me. thanks you
    – nicolas
    Sep 10, 2021 at 14:40

You must log in to answer this question.

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