\overset and align environment: how to get correct alignment?

The aligned-overset package now provides an easy solution for this: Just write

\documentclass{article}
...
\usepackage{aligned-overset}
\begin{document}
\begin{align*}
  f(x)&=g(x)\\
  \overset{something}&{=} h(x)
\end{align*}
\end{document}

Corresponding output


I would stack something on top of a relation using \stackrel{<stack>}{<relation>} (of something similar like \overset) and use mathtools's \mathclap. Space corrections can be accommodated using an appropriate \hspace:

enter image description here

\documentclass{article}
\usepackage{mathtools}

\begin{document}
\begin{align*}
  f(x) &= g(x) \\
       &\buildrel{something}\over{=} h(x)
\end{align*}

\begin{align*}
  f(x) &= g(x) \\
       &\stackrel{\mathclap{\text{something}}}{=} \hspace*{1.5em} h(x) \\
       &\overset{\mathclap{\text{something}}}{=} \hspace*{1.5em} h(x)
\end{align*}

\end{document}

However, avoid lengthy phrases on symbols. Instead you could define a new symbol to represent the relation.


You shouldn't be using \buildrel, which is not a supported command of LaTeX, but \overset.

You can get alignment using a phantom, but in my opinion it's better to add a side condition:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{amsmath}

\begin{document}
Possible way
\begin{align*}
f(x)&\overset{\hphantom{\text{something}}}{=}g(x)\\
    &\overset{\text{something}}{=} h(x)
\end{align*}

Better way
\begin{alignat*}{2}
f(x) &= g(x) \\
     &= h(x) &&\qquad\text{(something)}
\end{alignat*}
\end{document}

enter image description here

Tags:

Align