3

I would like to define a command with three arguments which stacks three symbols or text on top of each other. The \tmb command below does that but creates a bit too much vertical space between the middle and the bottom symbol. The commands \trialone and \trialtwo try to fix that with \raisebox but fail (see below). Then there is a contender based on \mystack, but if the middle symbol is a \to, then it is not vertically aligned with the division bar of a fraction right next to it, for example. Also, there is too little space around the three stacked symbols (to the left and right); see also below.

\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}
3
  • But do you want \sim or \to?
    – egreg
    May 7, 2021 at 14:53
  • With \fboxsep=-\fboxrule\fbox{$\sim$} you'll see the reason for the larger space below the tilde. However, a solution which works with the tilde might not work as well with other symbols.
    – campa
    May 7, 2021 at 14:57
  • @egreg: Ideally, I wanted to keep the symbols an argument (so changing), but \sim and \to are probably used in most cases (I used \tmb for long time and only realized that the spacing is off when combining it with \sim). @campa: interesting, so it's more a problem of the symbol \sim then... Ah, I didn't try to adjust that vertically, maybe that's easier. May 7, 2021 at 15:03

1 Answer 1

3

The difficult part is to keep the baseline pertaining to the middle symbol. This can be accomplished by typesetting a \vbox for the upper part, where the bottom is 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}

enter image description here

3
  • Great, thanks. If one wants to adjust the vertical space between "approx." and the arrow/tilde, one can change the \vspace{}. How can one adjust the space between the arrow/tilde and the "n large"? Ah, got it, one can add a \vspace{} right after the $2#$ part, I believe. May 7, 2021 at 15:16
  • @MariusHofert Like at the top, \noalign{\vspace{...}} (fill in the value) after \cr.
    – egreg
    May 7, 2021 at 15:24
  • Great, many thanks. I could also use [4] to create an optional argument that adds the same amount of \vspace above and below the middle symbol, so one can adjust it manually if required :-) May 7, 2021 at 15:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .