1

I'm using the \overset command and I would like to vertically align the overset values

Unaligned overset values

1
  • See if \vphantom can help.
    – nidhin
    Aug 18 at 8:14
2

We can add a vertical phantom, but we must be careful to preserve the correct spacing. I'd use a new macro \varoverset.

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newcommand{\varoverset}[2]{\binrel@{#2}%
  \binrel@@{\mathop{\vphantom{M}{#2}}\limits^{#1}}}
\makeatother

\begin{document}

\begin{gather*}
\overset{0}{\neg} Aa \overset{0}{\lor}
(\overset{0}{Mcc} \overset{0}{\leftrightarrow} \overset{1}{Mba})
\\
\varoverset{0}{\neg} Aa \varoverset{0}{\lor}
(\varoverset{0}{\mathit{Mcc}} \varoverset{0}{\leftrightarrow} \varoverset{1}{\mathit{Mba}})
\end{gather*}

\end{document}

enter image description here

The \binrel@/\binrel@@ construction is inherited from the original definition of \overset and takes care of spacing. The second argument of \varoverset is put in braces in order to make a \mathord out of it, otherwise the spacing with the \vphantom would be in general wrong.

Note also that if Mcc and Mba are multi-letter variables you should better put them into a \mathit (as I did in the second formula).

EDIT For full control you can define a new length to be used in general, and an optional parameter to change it locally.

\newlength{\varoversetheight}
\settoheight{\varoversetheight}{M}
\makeatletter
\newcommand{\varoverset}[3][\varoversetheight]{\binrel@{#3}%
  \binrel@@{\mathop{\vrule width\z@ height#1{#3}}\limits^{#2}}}
\makeatother
1

Here, I use a stack to create the overset. (I also steal campa's \binrel@ trick, +1). The advantage here is that the overset position is tune-able, either through the use of an optional argument on a case-by-case basis, or by resetting the default \oversetnorm value. This is handy if the height of the objects are unusually tall, for example, if hatted.

The MWE shows this default \oversetnorm value adjusted for the 2nd row.

\documentclass{article}
\usepackage{stackengine,amsmath}
\newcommand\oversetnorm{.7\normalbaselineskip}
\makeatletter
\newcommand\myoverset[3][\oversetnorm]{%
  \binrel@{#3}\binrel@@{\mathop{\ensurestackMath{%
  \stackengine{#1}{#3}{\scriptstyle#2}{O}{c}{F}{F}{L}}}}}
\makeatother
\begin{document}
\[
\myoverset{0}{\neg} Aa \myoverset{0}{\lor}
(\myoverset{0}{\mathit{Mcc}} \myoverset{0}{\leftrightarrow} \myoverset{1}{\mathit{Mba}})
\]
\renewcommand\oversetnorm{11pt}
\[
\myoverset{0}{\neg} Aa \myoverset{0}{\lor}
(\myoverset{0}{\mathit{\hat M\!cc}} \myoverset{0}{\leftrightarrow} \myoverset{1}{\mathit{\hat M\!ba}})
\]
\end{document}

enter image description here

3
  • Ooh, I was just adding the optional parameter too :-)
    – campa
    Aug 18 at 9:34
  • LOL, @campa. The war of measure-countermeasure continues unabated! Or else like high-stakes poker: I'll see your \binrel@ and raise you one \oversetnorm. Aug 18 at 9:35
  • Oh well, as long as the escalation leads to nicer TeX code it's fine :-D
    – campa
    Aug 18 at 9:55

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.