[Tex/LaTex] Aligning equality sign with overset text

alignamsmathvertical alignment

I'm typing a logic definition within an align environment that uses \overset{def}{=} from the amsmath environment.

However, the new sign is aligned vertically based on the equality sign, and not on the entire sign. In other words, the word def is not considered in the alignment, which produces a result that I don't like.

How can I correctly vertically align the sign?

An MWE (the spacing around the sign is not an issue):

\documentclass{article}
\usepackage{amsmath}

\begin{document}
The definition of the satisfaction relation $M,s,g \models \phi$, which specifies that formula $\phi$ is true under valuation $g$ in state $s$ of model $M$, is given below.
\begin{align*}
M,s,g &\models x &\overset{def}{=} \qquad &s = g(x)\\
M,s,g &\models n &\overset{def}{=} \qquad &V(n) = {s}\\
M,s,g &\models p &\overset{def}{=} \qquad &s \ \epsilon \ V(p)\\
\end{align*}

\end{document} 

Illustrative picture:

enter image description here

The equality signs are aligned vertically as per the red line.
However, the center of the new equality sign (\overset{def}{=}) is at the green line.
The new sign should move down until the green line overlaps with the red line (approximately anyway). Then the vertical alignment would be correct.

Best Answer

I would suggest that you put the def/equal sign in a column of its own:

Sample output

\documentclass{article}
\usepackage{amsmath}

\newcommand{\defeq}{\overset{\mathrm{def}}{=}}

\begin{document}
The definition of the satisfaction relation \( M,s,g \models \phi \), which specifies that formula \( \phi \) is true under valuation \( g \) in state \( s \) of model \( M \), is given below.
\begin{align*}
M,s,g &\models x &\defeq&&s &= g(x)\\
M,s,g &\models n &\defeq&&s&= V(n)\\
M,s,g &\models p &\defeq&&s &\in V(p)\\
\end{align*}

\end{document} 

Additional changes made

  • defined a command \defeq which typesets the def part in roman font.
  • added alignment of right-hand column added at =, line 2 swapped to s=V(n) for symmetry
  • \(...\) used instead of $...$

If you really want the symbol to be vertically centered, then there is a standard TeX command \vcenter which centers material with respect to the axis of the formula (roughly the height of the center of x). The argument to \vcenter is material in vertical mode, so you need to box up the contents. The naive version of this is:

Vertically centered sample

\documentclass{article}
\usepackage{amsmath}

\newcommand{\defeq}{\vcenter{\hbox{\( \overset{\mathrm{def}}{=} \)}}}

\begin{document}

The definition of the satisfaction relation \( M,s,g \models \phi \), which specifies that formula \( \phi \) is true under valuation \( g \) in state \( s \) of model \( M \), is given below.
\begin{align*}
M,s,g &\models x &\defeq&&s &= g(x)\\
M,s,g &\models n &\defeq&&s&= V(n)\\
M,s,g &\models p &\defeq&&s &\in V(p)\\
\end{align*}

\end{document}

You can add @daleif's smaller version of the font if you so wish, by putting \scriptscriptstyle before \mathrm.

A more sophisticated version of the command would be, as in How to capture the current math style?:

\usepackage{amsmath}
\usepackage{mathstyle}

\makeatletter
\newcommand{\defeq}{\vcenter{\hbox{\( \m@th\currentmathstyle
  \overset{\mathrm{def}}{=} \)}}}
\makeatother

which would resize in superscripts.