# reduce vertical space for \xrightarrow

I find the vertical spacing of amsmath's \xrightarrow too large for the underset. Is there an easy way to reduce it (i.e. put "below" close to the arrow, in the example)?

\documentclass{minimal}
\usepackage{amsmath}
\begin{document}
\fbox{$\xrightarrow[\fbox{below}]{\fbox{above}}$}
\end{document}


I looked at the arrow definition (ext@arrow, e.g. discussed in Understanding ext@arrows) and there, \limits^{}_{} is used.

PS. I am interested in a short and simple solution. I know how to built a new extensible arrow from scratch, but wanted to know if there is an easier solution.

• Welcome to TeX.SX! Just a note: prefer the article class instead of minimal for MWEs. See also Why should the minimal class be avoided? Mar 7 '15 at 1:40
• See if the answer to tex.stackexchange.com/q/94572/3954 helps you here. Mar 7 '15 at 2:22
• Short answer: no, if you want to rely on the same mechanism, which essentially is \mathop{<arrow>}\limits^{<above>}_{<below>} and where the spacing is hardwired in TeX (based on \fontdimen parameters of the math extension font). Mar 7 '15 at 9:50
• As above, so below! Oct 23 '20 at 8:08

Remedied the valid comment of mh256, creating macro \xxrightarrow[]{} that reduces the space of the underset, but allows for the length of the underset.

EDITED to make it \mathrel and also to use temp \box2 instead of \box0, which appears to be also used by \xrightarrow.

\documentclass{minimal}
\usepackage{amsmath,stackengine}
\stackMath
\newcommand\xxrightarrow[2][]{\mathrel{%
\setbox2=\hbox{\stackon{\scriptstyle#1}{\scriptstyle#2}}%
\stackunder[0pt]{%
\xrightarrow{\makebox[\dimexpr\wd2\relax]{$\scriptstyle#2$}}%
}{%
\scriptstyle#1\,%
}%
}}
\parskip 3pt
\begin{document}
\fbox{$\xxrightarrow[\fbox{below}]{\fbox{above}}$}

\fbox{$\xxrightarrow[\fbox{below is a long text}]{\fbox{above}}$}

$x \xxrightarrow[bottom]{top} y$

$x \xxrightarrow[a]{a} y$

$x \xrightarrow[a]{a} y$

\end{document}


• This is't an extensible arrow. The text below does not influence the length of the arrow in any way. Mar 7 '15 at 19:05
• @mh256 That is a good point. I will work to resolve that. Mar 7 '15 at 19:41
• @mh256 See revision. Mar 7 '15 at 19:52
• That's better. I don't understand why your solution has a minimum length of the arrow. ($x \xxrightarrow[a]{a} y$) Mar 7 '15 at 22:03
• @mh256 Apparently \box0 is already being used by \xrightarrow, so I merely changed over to \box2 to take care of the $x \xxrightarrow[a]{a} y$ use case. Also, I made the relation a \mathrel to obtain proper surrounding spacing. Mar 8 '15 at 2:26

Here is my solution.

\documentclass{minimal}
\usepackage{amsmath}
\usepackage{calc}
\begin{document}
\newcommand\myxrightarrow[2][]{
\xrightarrow[{\raisebox{1.25ex-\heightof{$\scriptstyle#1$}}[0pt]{$\scriptstyle#1$}}]{#2}%
}
\noindent
\fbox{$\xrightarrow[\fbox{below}]{\fbox{above}}$}
\fbox{$\myxrightarrow[\fbox{below}]{\fbox{above}}$}\\
\fbox{$\xrightarrow[below]{above}$}
\fbox{$\myxrightarrow[below]{above}$}\\
\fbox{$\xrightarrow[aaa]{above}$}
\fbox{$\myxrightarrow[aaa]{above}$}\\
\fbox{$\xrightarrow[\int^2]{above}$}
\fbox{$\myxrightarrow[\int^2]{above}$}
\end{document}


Advantage: Command with just one line

Disadvantage: Line height is not as small as it could be (see aaa example).