如何正确堆叠三个符号(例如,汇聚箭头或波浪号上方和下方的符号或文本)?

如何正确堆叠三个符号(例如,汇聚箭头或波浪号上方和下方的符号或文本)?

我想定义一个带有三个参数的命令,将三个符号或文本堆叠在一起。\tmb下面的命令可以做到这一点,但在中间和底部符号之间创建了太多的垂直空间。命令\trialone\trialtwo尝试使用修复该问题\raisebox但失败了(见下文)。然后有一个基于的竞争者\mystack,但如果中间符号是\to,那么它就不会与紧挨着它的分数的除法线垂直对齐,例如。此外,三个堆叠符号周围的空间太小(左侧和右侧);另请参见下文。

\documentclass{scrartcl}

\usepackage{amsmath}
\newcommand{\tmb}[3]{\underset{{\scriptscriptstyle #3}}{\overset{{\scriptscriptstyle #1}}{#2}}}% *t*op, *m*iddle, *b*ottom command
\newcommand{\trialone}[3]{\underset{{\scriptscriptstyle\raisebox{2mm}{#3}}}{\overset{{\scriptscriptstyle #1}}{#2}}}
\newcommand{\trialtwo}[3]{\underset{{\raisebox{2mm}{\tiny #3}}}{\overset{\scriptscriptstyle #1}{#2}}}
\newcommand{\mystack}[3]{\substack{#1\\{\textstyle #2}\\[-0.3mm]#3}}

\begin{document}
\begin{itemize}
\item LHS $\tmb{\text{approx.}}{\to}{\text{$n$ large}}$ RHS. Here you see too much vertical space for what's below the arrow.
\item LHS $\tmb{\text{approx.}}{\sim}{\text{$n$ large}}$ RHS. Here you also see too much vertical space for what's below the tilde.
\item LHS $\trialone{\text{approx.}}{\sim}{\text{$n$ large}}$ RHS. Font size not respected.
\item LHS $\trialtwo{\text{approx.}}{\sim}{\text{$n$ large}}$ RHS. Fails if the
  command contains scriptscriptstyle instead of tiny. Still, the raisebox
  command does not seem to work.
\item LHS $\mystack{\text{approx.}}{\sim}{\text{$n$ large}}$ RHS. Looks okay, but the tilde and other middle symbols are not vertically aligned correctly, see
  \begin{align*}
    \frac{A}{B} \mystack{\text{approx.}}{\to}{\text{$n$ large}} \frac{C}{D} \quad\text{versus}\quad \frac{A}{B}\tmb{\text{approx.}}{\to}{\text{$n$ large}} \frac{C}{D}.
  \end{align*}
  We see that the arrow on the left is vertically not aligned with the division bars of the two fractions. Also, there is not sufficient space around the command. None of these problems appears on the right (there is only too much vertical space between the arrow and the ``$n$ large''.
\end{itemize}
\end{document}

答案1

困难的部分是保持与中间符号相关的基线。这可以通过\vbox在上面部分排版 a 来实现,而在下面部分排版 a \vtop

\documentclass{scrartcl}

\usepackage{amsmath}

\makeatletter
\newcommand{\tmb}[3]{%
  \mathrel{%
    \vbox{\offinterlineskip\m@th
      \ialign{%
        \hfil##\hfil\cr
        $\scriptscriptstyle#1\mathstrut$\cr
        \noalign{\vspace{0.3ex}}
        \vtop{%
          \ialign{%
            \hfil##\hfil\cr
            $#2$\cr
            $\scriptscriptstyle#3\mathstrut$\cr
          }%
        }\cr
      }%
    }%
  }%
}
\makeatother

\begin{document}

\[
\frac{X}{2}
\tmb{\text{approx.}}{\to}{n\text{ large}}
\frac{X}{2}
\tmb{\text{approx.}}{\sim}{n\text{ large}}
\frac{X}{2}
\]

\end{document}

在此处输入图片描述

相关内容