![如何正确堆叠三个符号(例如,汇聚箭头或波浪号上方和下方的符号或文本)?](https://linux22.com/image/433240/%E5%A6%82%E4%BD%95%E6%AD%A3%E7%A1%AE%E5%A0%86%E5%8F%A0%E4%B8%89%E4%B8%AA%E7%AC%A6%E5%8F%B7%EF%BC%88%E4%BE%8B%E5%A6%82%EF%BC%8C%E6%B1%87%E8%81%9A%E7%AE%AD%E5%A4%B4%E6%88%96%E6%B3%A2%E6%B5%AA%E5%8F%B7%E4%B8%8A%E6%96%B9%E5%92%8C%E4%B8%8B%E6%96%B9%E7%9A%84%E7%AC%A6%E5%8F%B7%E6%88%96%E6%96%87%E6%9C%AC%EF%BC%89%EF%BC%9F.png)
我想定义一个带有三个参数的命令,将三个符号或文本堆叠在一起。\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}