在等式上方添加箭头和文字

在等式上方添加箭头和文字
\documentclass{article}

\usepackage{amsmath}

\begin{document}
\begin{equation}
    \mathbf{v}_{\textnormal{h}}=\mathbf{v}_{\textnormal{h},0}\left(X_{\textnormal{m}}, X_{\textnormal{s}}, z\right)+\epsilon\mathbf{v}_{\textnormal{h},1}\left(X_{\textnormal{m}},X_{\textnormal{s}}, z\right)+\epsilon^2\mathbf{v}_{\textnormal{h},2}\left(X_{\textnormal{m}},X_{\textnormal{s}}, z\right)+\cdots\,.
\end{equation}
\end{document}

问题:我该如何标记 epsilon?我想要一个箭头 (\downarrow) 指向方程式,并在箭头下方显示文字。

答案1

您可以使用 来实现\overset,其中上部tabular在适当大小下宽度为零,即\scriptsize

如果您有多个注释,您可能需要帮助 TeX 以使它们处于相同的垂直位置。

\documentclass{article}
\usepackage{amsmath}

\newcommand{\annot}[2]{% #1 symbol to annotate, #2 = text
  \overset{%
    \makebox[0pt]{%
      \normalfont\scriptsize
      \begin{tabular}{@{}c@{}} #2 \\ $\downarrow$ \end{tabular}%
    }%
  }{\mathstrut #1}%
}

\begin{document}

\begin{equation}
\mathbf{v}_{\mathrm{h}}=
\mathbf{v}_{\mathrm{h},0}(X_{\mathrm{m}},X_{\mathrm{s}}, z)
  +\annot{\epsilon}{interesting}\mathbf{v}_{\mathrm{h},1}(X_{\mathrm{m}},X_{\mathrm{s}}, z)
  +\epsilon^2\mathbf{v}_{\mathrm{h},2}(X_{\mathrm{m}},X_{\mathrm{s}}, z)
  +\dotsb.
\end{equation}

\begin{equation}
\mathbf{v}_{\mathrm{h}}=
\mathbf{v}_{\mathrm{h},0}(X_{\mathrm{m}},X_{\mathrm{s}}, z)
  +\annot{\epsilon\vphantom{\epsilon^2}}{interesting}
   \mathbf{v}_{\mathrm{h},1}(X_{\mathrm{m}},X_{\mathrm{s}}, z)
  +\annot{\epsilon^2}{more interesting}
   \mathbf{v}_{\mathrm{h},2}(X_{\mathrm{m}},X_{\mathrm{s}}, z)
  +\dotsb.
\end{equation}

\end{document}

请注意省略了无用的\left\right标记,但也\dotsb代替了\cdots

在此处输入图片描述

您可以修改代码以允许上方和下方注释:使用 获得下方定位\annot*

\documentclass{article}
\usepackage{amsmath}

\NewDocumentCommand{\annot}{smm}{%
  % if *, below, otherwise above
  % #2 = symbol to annotate
  % #3 = text
  \IfBooleanTF{#1}{%
    \innerannot{\underset}{#2}{#3}{\textuparrow}%
  }{%
    \innerannot{\overset}{#2}{\textdownarrow}{#3}%
  }%
}
\NewDocumentCommand{\innerannot}{mmmm}{%
  #1{% \overset or underset
     \makebox[0pt]{%
       \normalfont\scriptsize
       \begin{tabular}{@{}c@{}} #4 \\ #3 \end{tabular}%
    }%
  }{\mathstrut #2}%
}

\begin{document}

\begin{equation}
\mathbf{v}_{\mathrm{h}}=
\mathbf{v}_{\mathrm{h},0}(X_{\mathrm{m}},X_{\mathrm{s}}, z)
  +\annot{\epsilon}{interesting}\mathbf{v}_{\mathrm{h},1}(X_{\mathrm{m}},X_{\mathrm{s}}, z)
  +\epsilon^2\mathbf{v}_{\mathrm{h},2}(X_{\mathrm{m}},X_{\mathrm{s}}, z)
  +\dotsb.
\end{equation}

\begin{equation}
\mathbf{v}_{\mathrm{h}}=
\mathbf{v}_{\mathrm{h},0}(X_{\mathrm{m}},X_{\mathrm{s}}, z)
  +\annot{\epsilon\vphantom{\epsilon^2}}{interesting}
   \mathbf{v}_{\mathrm{h},1}(X_{\mathrm{m}},X_{\mathrm{s}}, z)
  +\annot{\epsilon^2}{more interesting}
   \mathbf{v}_{\mathrm{h},2}(X_{\mathrm{m}},X_{\mathrm{s}}, z)
  +\dotsb.
\end{equation}

\begin{equation}
\mathbf{v}_{\mathrm{h}}=
\mathbf{v}_{\mathrm{h},0}(X_{\mathrm{m}},X_{\mathrm{s}}, z)
  +\annot{\epsilon}{interesting}
   \mathbf{v}_{\mathrm{h},1}(X_{\mathrm{m}},X_{\mathrm{s}}, z)
  +\annot*{\epsilon^2}{more interesting}
   \mathbf{v}_{\mathrm{h},2}(X_{\mathrm{m}},X_{\mathrm{s}}, z)
  +\dotsb.
\end{equation}

\end{document}

在此处输入图片描述

答案2

以下解决方案提供了两个用户宏:\explainabove\explainbelow。它们分别使用\overset\underset,它们是包提供的宏amsmath,以及包\mathclap提供的宏mathtools。(mathtools包是包的超集amsmath。)这样,您只需编写\explainabove{some text}{\epsilon}和 \explainbelow{more text}{\epsilon^2} 即可提供所需的注释。

在此处输入图片描述

\documentclass{article}
\usepackage{mathtools} % for '\mathclap' macro; load 'amsmath' automatically

%% two new user macros
\newcommand\explainabove[2]{%
    \overset{\overset{\mathclap{\textnormal{#1}}}{\downarrow}}{#2\mathstrut}}
\newcommand\explainbelow[2]{%
    \underset{\underset{\mathclap{\textnormal{#1}}}{\uparrow}}{#2\mathstrut}}

\begin{document}

\begin{equation}
 \mathbf{v}_{\mathrm{h}}
=\mathbf{v}_{\mathrm{h},0}(X_{\mathrm{m}},X_{\mathrm{s}},z)
+\explainabove{some text}{\epsilon}
 \mathbf{v}_{\mathrm{h},1}(X_{\mathrm{m}},X_{\mathrm{s}},z)
+\explainbelow{more text}{\epsilon^2}
 \mathbf{v}_{\mathrm{h},2}(X_{\mathrm{m}},X_{\mathrm{s}}, z)
+\dotsb
\end{equation}

\end{document}

相关内容