如何在數學模式下實現箭頭「內」的文字?

如何在數學模式下實現箭頭「內」的文字?

我知道\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}

相關內容