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

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

| improve this answer | |
  • 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
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.