수학 모드에서 화살표 "내부"에 텍스트를 구현하는 방법은 무엇입니까?

수학 모드에서 화살표 "내부"에 텍스트를 구현하는 방법은 무엇입니까?

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

관련 정보