Vertical alignment of \stackengine stacks
The default stack type in stackengine
are "S
hort" stacks that preserve the amount of empty vertical gap between letters in the stack. But there are also "L
ong" stacks that preserve the baselineskip. Therefore, merely invoke \renewcommand\stacktype{L}
.
The default baselineskip is \normalbaselineskip
, but you can reset it with \setstackgap{L}{<length>}
. Or else you can pass an optional argument to the particular stack: \stackon[<length>]{...}
.
\documentclass{article}
\usepackage{stackengine}
\begin{document}
\renewcommand\stacktype{L}
\stackon{a}{w}\stackon{b}{x} \stackon{c}{y}\stackon{d}{z}
\end{document}
The package documentation, https://ctan.org/pkg/stackengine, lays this all out clearly.
A work-around, with \vphantom
and \smash
:
\documentclass{article}
\usepackage{stackengine, amsmath}
\begin{document}
\stackon{a\vphantom{b}}{w}\stackon{b}{x} \stackon{c\vphantom{d}}{\smash[b]{y}}\stackon{d}{z}
\end{document}
Here's how I'd do it:
\documentclass{article}
\newcommand{\aw}[2]{%
\leavevmode\vbox{%
\offinterlineskip
\halign{%
\hfil##\hfil\cr
\vphantom{y}#2\cr
\noalign{\vskip0.4pt}
\vphantom{b}#1\cr
}%
}%
}
\begin{document}
\aw{a}{w}\aw{b}{x} \aw{c}{y}\aw{d}{z} \aw{d}{q}
\end{document}
A version where the letters at the top are smaller:
\documentclass{article}
\makeatletter
\newcommand{\aw}[2]{%
\leavevmode\vbox{%
\check@mathfonts
\offinterlineskip
\halign{%
\hfil##\hfil\cr
\fontsize{\ssf@size}{0}\selectfont
\vphantom{y}#2\cr
\noalign{\vskip0.4pt}
\vphantom{b}#1\cr
}%
}%
}
\makeatother
\begin{document}
\aw{a}{w}\aw{b}{x} \aw{c}{y}\aw{d}{z} \aw{d}{q}
\end{document}