What is the shortest and convenient way to Put reference above equal sign and refer to it in text, i.e. do something like this:

Sample code

It can be done manually, by using \stackrel{}{} command and manual numbering. My question is: can it be done in a smarter way?

  • Please clarify what (1) stands for. Is it supposed to be an automatically generated number (an equation number, maybe?), is it a cross-reference to some other result (a numbered theorem, maybe?), or is it something else? Please advise. – Mico Jul 8 '18 at 17:20

You haven't stated what you consider to be "shortest", "convenient", "smart", or "reference". However, I'll assume that a LaTeX macro (called \numeq in the example below) which takes one argument comes reasonably close to satisfying your objective.

enter image description here

\begin{equation} \label{eq:xyz}
X \numeq{n} Y+Z
A cross-reference to equation \eqref{eq:xyz}.

Below, I have defined a macro \labelrel that I believe should do what you want. It takes two arguments of which the first is the (relation) symbol you would like to label and the second is a label name. The labels are incremented automatically and you can refer to them using \eqref as if they were equations.



\newcounter{relctr} %% <- counter for relations
\everydisplay\expandafter{\the\everydisplay\setcounter{relctr}{0}} %% <- reset every eq
\renewcommand*\therelctr{\alph{relctr}} %% <- label format

\AtBeginDocument{\let\originallabel\label} %% <- store original definition


  Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
  eirmod invidunt, and therefore
      X \labelrel={myeq:equality} Y + Z \labelrel\leq{myeq:inequality} \ldots.
  The equality~\eqref{myeq:equality} in equation~\eqref{myeq} was proven in Theorem~123,
  and the inequality~\eqref{myeq:inequality} is self-explanatory.
  Here is another equation,
      f(A \cap B) \labelrel\subseteq{somelabelname} f(A) \cap f(B)
  which contains an inclusion~\eqref{somelabelname} unrelated to equation~\eqref{myeq}.


enter image description here

A few remarks:

  • I'm using letters instead of numbers to avoid any clashes with equation numbers. To use numbers, replace (both instances of) \alph by \arabic above.

  • The labels start with (a) in every equation. If you don't want this you should remove the \everydisplay line. If you want the numbering to start over at the beginning of every section you should use \newcounter{relctr}[section].

  • It is also possible to refer to the relations in equation (1) as (1a), (1b), etc without changing their tags. This is accomplished by replacing the \therelctr line by \renewcommand*\therelctr{\theequation\alph{relctr}}. It does mean that every equation that has labelled relations must be numbered.

  • I'm storing the definition of \label in \originallabel because amsmath redefines the \label macro inside equations. I do this \AtBeginDocument in case any packages (like hyperref) loaded after this code change the definition.

  • I'm using \mathstrut (which is equivalent to \phantom() to ensure that every label is placed at the same height, independent of the height of the relation it is decorating. You can remove it if you don't like this.

  • \begingroup and \endgroup limit the scope of the effect of \refstepcounter. Without them it would no longer be possible to reference the equation itself.


Perhaps this is what you are looking for? I've assumed that you basically want the equation reference number (which would normally appear on the right hand side of the equation) changed to be positioned above the equal sign.

  • Label the equations as you normally would using \label{...}
  • Use \stackrel{(\ref{...})}{=} to get the reference number above the equal sign.
  • At the end of the equation use the custom command \nonumberthis which suppresses the reference number from appearing at the right hand side but keeps the counter going.

enter image description here




\noindent \ldots We arrive to relationship
   X \stackrel{(\ref{mylabel})}{=} Y + Z = \ldots, \nonumberthis
where in (\ref{mylabel}) we used Theorem 123. 
And another example
   A \stackrel{(\ref{mylabel2})}{=} B + C = \ldots, \nonumberthis
is given by the reference (\ref{mylabel2}).


The \nonumberthis command was based off this answer .

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.