7

I would need to write a few letters above certain syllables in a normal text. I've found this great \stackengine package, which seems to do the job.

\documentclass{article}
\usepackage{stackengine}
\begin{document}
\stackon{a}{w}\stackon{b}{x} \stackon{c}{y}\stackon{d}{z}
\end{document}

enter image description here

However, due to the different height of the letters, the vertical position of the stacked pieces of text is not even. How is it possible to balance somehow out this difference and create a kind of secondary line of the stacks above the main line?

3 Answers 3

7

The default stack type in stackengine are "Short" stacks that preserve the amount of empty vertical gap between letters in the stack. But there are also "Long" 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}

enter image description here

The package documentation, https://ctan.org/pkg/stackengine, lays this all out clearly.

enter image description here

1
  • It works, although I need to add extra space due to ascenders. Regarding the guide, which I consulted, the things that look clear and evident for you, might not be the case for other users. I would be glad if you could add my example to it, as I find it more intuitive. Feb 18, 2019 at 7:12
2

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} 

enter image description here

2
  • 1
    +1 Even though it's not elegant, it works. I assume you don't need amsmath in the MWE, do you? Feb 17, 2019 at 19:05
  • 2
    I do need it, but only for the optional argument of \smash (it neutralises the descender of y). I added it just in case smashing the whole glyph has some side effects in particular contexts. That being said, I really don't know if there's something more elegant.
    – Bernard
    Feb 17, 2019 at 19:09
2

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}

enter image description here

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}

enter image description here

You must log in to answer this question.

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