# Put reference above inequality symbol within align* environment

I have a chain of vertically aligned inequalities that need explanations and I'm trying to put numbers (1,2,3,...) above each inequality symbol so as to reference them outside the align* environment and explain each passage. Can anybody help with this?

## 2 Answers

Here's a way:

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newcommand{\markthis}[3]{% #1 = marker, #2 = label, #3 = relation
\overset{% the marker and the label
\textup{\makebox[0pt]{#1}}%
\def\@currentlabel{#1}%
\ltx@label{#2}%
}{% the relation
#3%
}%
}
\makeatother

\begin{document}

\begin{align*}
(1+x)^{n+1}
& \markthis{(1)}{b:1}{=} (1+x)(1+x)^n \\
& \markthis{(2)}{b:2}{\ge} (1+x)(1+nx) \\
& \markthis{(3)}{b:3}{=} 1+x+nx+nx^2 \\
& \markthis{(4)}{b:4}{\ge} 1+(n+1)x
\end{align*}
We have~\ref{b:1} by definition; \ref{b:2}~by the induction hypothesis;
\ref{b:3}~by algebra; \ref{b:4}~because $nx^2\ge0$.

\begin{alignat*}{2}
(1+x)^{n+1}
& = (1+x)(1+x)^n  &\qquad& \text{(definition)} \\
& \ge (1+x)(1+nx) &&      \text{(induction hypothesis)} \\
& = 1+x+nx+nx^2   &&      \text{(algebra)} \\
& \ge 1+(n+1)x    &&      \text{(because $nx^2\ge0$)}
\end{alignat*}

\end{document}


I added a second way to typeset the same, which I'd prefer.

The trick is to use \ltx@label because amsmath would reject \label and to set the reference suitably.

With use of the stackengine package:

\documentclass[margin=3mm,varwidth]{standalone}
\usepackage{amsmath}
\usepackage{stackengine}
\newcommand\marksymb[2]{\,\stackon{#1}{\scriptscriptstyle (#2)}\, }
\stackMath

\begin{document}
\begin{align}
A   & \marksymb{>}{1} B   \\
C+D & \marksymb{=}{2} E   \\
C+D & = E
\end{align}
\end{document}


• Thanks. Later in the document I simply refer to those by typing (1), (2) etc, or there's a command?
– Karl
Sep 19, 2023 at 12:02
• @Karl, simple as (1), (2) etc. For referencing for example by \ref˙{,,,} you should stick with egreg solution. Sep 19, 2023 at 12:36