3

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

Unaligned overset values

campa
  • 31,130
Frank
  • 421

2 Answers2

3

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
campa
  • 31,130
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