6

I am aware of \xrightarrow and other options using amsmath, but instead having the text over the arrow, I am looking for something like this:

expression --text--> another expression

Can this be achieved using amsmath (or some other library)?

If not, then how can I define this myself?

4 Answers 4

4

I'd use smaller type vertically centered with respect to the math axis:

\documentclass{article}
\usepackage{amsmath}

\newcommand{\crightarrow}[1]{%
  \relbar\joinrel\joinrel\relbar\mathrel{\vcentertext{#1}}\rightarrow
}

\newcommand{\vcentertext}[1]{%
  \vcenter{\hbox{\scriptsize\smallstrut#1}}%
}
\newcommand{\smallstrut}{\vrule height 1.5ex depth 0.5ex width 0pt }

\begin{document}

$a_n \crightarrow{goes to} a$

$a_n \crightarrow{oes} a$

$a_n \crightarrow{bbb} a$

$a_n \crightarrow{ppp} a$

\end{document}

enter image description here

6

I propose this:

\documentclass{article}
\usepackage{amsmath}

\newcommand{\mytextarrow}[1]{\mathrel{\relbar\mkern-10mu\relbar\mkern-3.5mu\raisebox{0.25ex}{\scriptsize#1}\!\rightarrow}}

\begin{document}

\begin{equation*}
2 + 2 \mytextarrow{goes to} 4
\end{equation*}

\end{document} 

enter image description here

2
  • I'd \vcenter the text in smaller type.
    – egreg
    Commented Feb 7, 2016 at 21:32
  • Why of course! How comes I didn't think of it? Thanks for the suggestion, I'll add it at once.
    – Bernard
    Commented Feb 7, 2016 at 21:38
2
\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\newlength\tmplength
\newcommand*\textarrow[2][3em]
  {\mathrel{\vcenter{\hbox{\settowidth\tmplength{\scriptsize#2}%
                           \tikz[font=\scriptsize]
                             \draw[->](0,0)--node[fill=white,midway]{#2}
                             ++({#1+\the\tmplength},0);}}}}

and you can use

$a \textarrow{foo} b$
$a \textarrow[5em]{bar} b$
$a \textarrow[10em]{baz} b$

enter image description here

1
  • I can't use width("\noexpand\scriptsize#2") properly, if someone could add that (removing the need of \newlength\tmplength and \settowidth, etc. I would appreciate it.
    – Manuel
    Commented Feb 7, 2016 at 22:52
1

enter image description here

\documentclass{article}

\usepackage{amsmath}

\newcommand{\textarrow}[1]{-\text{#1}\to}

\begin{document}

\begin{equation*}
2 + 2 \textarrow{goes to} 4
\end{equation*}

\end{document}
2
  • The dash --- has different width.
    – Sigur
    Commented Feb 7, 2016 at 18:23
  • It is better to use -\text{#1}\to.
    – Sigur
    Commented Feb 7, 2016 at 18:26

You must log in to answer this question.

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