数式モードで矢印の「内側」にテキストを実装するにはどうすればよいですか?

数式モードで矢印の「内側」にテキストを実装するにはどうすればよいですか?

\xrightarrowおよび を使用した他のオプションがあることは承知していますamsmathが、矢印の上にテキストを表示する代わりに、次のようなものを探しています。

expression --text--> another expression

amsmath (または他のライブラリ) を使用してこれを実現できますか?

そうでない場合、これを自分でどのように定義できるでしょうか?

答え1

数式軸に対して垂直中央に配置された小さい文字を使用します。

\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}

ここに画像の説明を入力してください

答え2

私はこれを提案します:

\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} 

ここに画像の説明を入力してください

答え3

\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);}}}}

そして、あなたは使うことができます

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

ここに画像の説明を入力してください

答え4

ここに画像の説明を入力してください

\documentclass{article}

\usepackage{amsmath}

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

\begin{document}

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

\end{document}

関連情報