0

I'd like to create a version of the command \tmb{}{}{} (for stacking 3 pieces of information in the order top, middle, bottom) from egreg's solution here that allows one to use text input as first and third arguments (instead of math formulas; writing \tmb{\text{}}{}{\text{}} repeatedly is tedious). Here's my attempt and what's wrong with it:

\documentclass{scrartcl} \usepackage{amsmath} \usepackage{mathtools} % See https://tex.stackexchange.com/questions/596113/how-to-properly-stack-three-symbols-e-g-symbols-or-text-above-and-below-conver/596116#596116 \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 % My trial to define a version that accepts text as 1st and 3rd argument \makeatletter \newcommand{\tmbtext}[3]{% \mathrel{% \vbox{\offinterlineskip\m@th \ialign{% \hfil##\hfil\cr \tiny#1\strut\cr \noalign{\vspace{0ex}} \vtop{% \ialign{% \hfil##\hfil\cr $#2$\cr \tiny#3\strut\cr }% }\cr }% }% }% } \makeatother \begin{document} \begin{alignat*}{2} &\mathclap{\tmb{n=km}{=}{\text{def.}}} \qquad&& \text{... the original version with formulas and text above/below ``$=$''}\\ &\mathclap{\tmbtext{$n=km$}{=}{def.}} \qquad&& \text{... text version, but formula now has too much horizontal space around ``$=$''}\\ &\mathclap{\tmbtext{$\scriptstyle n=km$}{=}{def.}} \qquad&& \text{... fixes the horizontal spacing problem but providing \texttt{scriptstyle} every time is tedious} \end{alignat*} \end{document} 

enter image description here

I'd ideally like to be able to provide text or a formula enclosed in $ $ symbols (just like the second version above), but have the output displayed as in the third version (without the need to manually provide \scriptstyle or other commands). Is that possible?

2
  • Sorry, but you contradict yourself. Yesterday you wanted space around relation symbols, today you don't; and you're asking to have text at the top and bottom, then you use $...$. What's your real aim? Commented Apr 24 at 16:22
  • ... indeed, more space in math mode, less in text mode (neither seems to be straightforward and so I settled with the more compact version in math mode - which indeed looked fine in most actual, non-minimal use cases). Commented Apr 25 at 9:01

1 Answer 1

3

I don't see what's the purpose of avoiding \text in one argument, but having $...$ in the other…

Anyway…

\documentclass{scrartcl} \usepackage{amsmath} \usepackage{mathtools} % See https://tex.stackexchange.com/questions/596113/how-to-properly-stack-three-symbols-e-g-symbols-or-text-above-and-below-conver/596116#596116 \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 }% }% }% } \newcommand{\tmbtext@aux}[1]{% \fontsize{\ssf@size}{\fpeval{1.2*\ssf@size}}\selectfont\strut \thickmuskip=0mu \medmuskip=0mu #1% } \newcommand{\tmbtext}[3]{% \mathrel{% \vbox{\offinterlineskip\m@th\check@mathfonts \ialign{% \hfil##\hfil\cr \tmbtext@aux{#1}\cr \noalign{\vspace{0.3ex}} \vtop{% \ialign{% \hfil##\hfil\cr $#2$\cr \tmbtext@aux{#3}\cr }% }\cr }% }% }% } \makeatother \begin{document} \begin{gather*} A \tmbtext{aaa}{=}{bbb} B \tmbtext{bbb}{=}{aaa} C \tmbtext{$n=km$}{=}{def.} D \\ A \tmb{\text{aaa}}{=}{\text{bbb}} B \tmb{\text{bbb}}{=}{\text{aaa}} C \tmb{n=km}{=}{\text{def.}} D \end{gather*} \end{document} 

output

1
  • Thanks a lot, egreg (I shall not bother you again for some while...). I understand your point \text{} vs $ $, but I have a solid 4-digit number of calls and a vast majority with text, so writing $ $ instead of \text{} is indeed much more convenient. I also wrote a nice wrapper that calls the command with \clap{} around the first and third argument, to get correct vertical alignment of equations with arguments extending beyond the width of =. Thanks again for your great help. Commented Apr 25 at 9:05

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.