# Vertically align characters raised with \stackrel

I learned from Stefan's reply to Putting a character above another character to use \stackrel in math mode to do just that. I'm using that right now to mark segments of a word as having a high (H) or low (L) tone. In some words, however, the characters that I put H or L above are of different heights. How can I align the raised characters H and L vertically?

\documentclass{article}
\usepackage{amsmath}
\begin{document}
h$\stackrel{\text{L}}{\text{a}}$nd$\stackrel{\text{H}}{\text{l}}$
\end{document}


EDIT: The accepted answer to Adjusting vertical and horizonal spacing in \stackrel suggests (like Barbara below) to use \strut for each element. When using double spacing, however, this raises the characters way too high.

\documentclass{article}
\usepackage{amsmath,setspace}
\doublespacing
\begin{document}
h$\stackrel{\text{L}}{\strut{\text{a}}}$nd$\stackrel{\text{H}}{\strut{\text{l}}}$
\end{document}


• you can add \strut to the lower element to ensure that it will always be full height. Jun 16 '13 at 16:12
• @barbarabeeton: I tried that now, and it raises the L even higher than the H. I could, of course, add \strut to both, but I'd prefer to not raise the characters more than necessary. Jun 16 '13 at 16:16

You can add a \strut to make them vertically aligned. Or add a \vphantom only when necessary.

This is a relatively low-level implementation:

\documentclass{article}

% cf. \oalign and \mathstrut in LaTeX kernel
\newcommand\textoverset[3][(]{%
\leavevmode\vbox{%
\baselineskip0pt \lineskip.25ex
\ialign{\hfil##\hfil\crcr
\scriptsize#2\cr
\vphantom{#1}#3\crcr}}}

\begin{document}

h\textoverset{L}{a}nd\textoverset{H}{l}


• The second example prevents the raised characters from being raised too high when \doublespacing is used, but what is the reason that the H is lower in the second example than in the first example (and in my original example)? Jun 16 '13 at 16:39
• @Sverre: \strut may be very high if you set \doublespacing. You can use other struts you like. Jun 16 '13 at 16:41
• I'd avoid \strut for this. Better using the height of a letter with ascenders as \vphantom. Jun 16 '13 at 16:43
• @Sverre: My macro sets \vphantom with the optional argument if exist, or use \vphantom{(}. The second example use the letter l for \vphantom, which is a little lower than symbol (. Jun 16 '13 at 16:49