6

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}

enter image description here


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}

enter image description here

Sverre
  • 20,729
  • 2
    you can add \strut to the lower element to ensure that it will always be full height. – barbara beeton 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. – Sverre Jun 16 '13 at 16:16

1 Answers1

5

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}}}

\linespread{3}

\begin{document}

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

h\textoverset[l]{L}{a}nd\textoverset[]{H}{l}% add a template manually

\end{document}

enter image description here

Leo Liu
  • 77,365
  • 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)? – Sverre Jun 16 '13 at 16:39
  • @Sverre: See my update. – Leo Liu Jun 16 '13 at 16:39
  • @Sverre: \strut may be very high if you set \doublespacing. You can use other struts you like. – Leo Liu Jun 16 '13 at 16:41
  • I'd avoid \strut for this. Better using the height of a letter with ascenders as \vphantom. – egreg Jun 16 '13 at 16:43
  • I can't follow this discussion now. And I don't understand why Leo's two examples have different heights for the raised characters. Could someone dumb this down a bit for me (I'm also curious what your suggestion entails, egreg)? – Sverre Jun 16 '13 at 16:45
  • @egreg: So I use ( now. – Leo Liu Jun 16 '13 at 16:45
  • 2
    @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 (. – Leo Liu Jun 16 '13 at 16:49
  • How can I simplify your command if I don't need to use the \vphantom option? In practice, I just created two different commands: One for adding H and L above x-height characters characters (like a, e, o, u, n), and one for l-height characters (so far only l). I.e. I no longer need the ability to add a custom character when needed. – Sverre Jun 18 '13 at 19:23