9

I am trying to add equation names besides the equation numbers but, in addition, in such a way that \eqref inserts just the number.

Inspired by the top answer in Add equation name underneath equation number, I tried the following solution:

\documentclass{article}
\usepackage{amsmath}
\newcommand\mylabel[2]{\label{#1} \\[-\baselineskip] \tag*{#2\ \hphantom{(\ref{#1})}}}

\begin{document}

\begin{align}
f(x) = a \mylabel{eq:a}{Constant} \\
h(x) = ax^2+bx+c \mylabel{eq:b}{Quadratic}
\end{align}

Equations \eqref{eq:a} and \eqref{eq:b} look OK\dots 

\begin{align}
j(x) = \varinjlim_{C_j} \mylabel{eq:c}{Way too low!}
\end{align}

\dots but the method fails in style for Equation \eqref{eq:c}.

\end{document}

enter image description here


As you can see, the trick I used is to write the equation name in a new line and then lift it by -\baselineskip. For simple equations as (1) or (2) I get exactly what I want. But indeed, this is shoddy work and it fails as soon as the equation gets a little more complicated, e.g. for (3).

I don't know whether I could use another length instead of -\baselineskip so that I always get the correct lift, or whether there is a more elegant (and not too complicated) way to achieve what I want.

summer
  • 1,474
  • 1
    This seems the same problem as in http://tex.stackexchange.com/questions/166580/writing-an-equation-with-the-units-positioned-off-right – egreg Apr 28 '14 at 14:12

2 Answers2

7

Based on the answer at How to put a text label *before* an equation?, I just moved the label from the left to the right. In this MWE, I use the flalign environment to accomplish the task. In the linked answer, there is also a method employing stacks, if flalign is not right for your need.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\noindent text
\begin{flalign}
\phantom{\text{Constant}}&&f(x) = a&&\text{Constant}\label{eq:a}\\
\phantom{\text{Quadratic}}&&h(x) = ax^2+bx+c&&\text{Quadratic}\label{eq:b}
\end{flalign}
Equations \eqref{eq:a} and \eqref{eq:b} look OK\dots 
\begin{flalign}
\phantom{\text{Just right!}}&&j(x) = \varinjlim_{C_j}
&&\text{Just right!}\label{eq:c}
\end{flalign}
\dots and the method no longer fails in style for Equation \eqref{eq:c}.
\end{document}

enter image description here

This process can be streamlined with the macro

\newcommand\nameeq[2]{\phantom{\text{#2}}&&#1&&\text{#2}}

and the following usage:

\begin{flalign}
\nameeq{f(x) = a}{Constant}\label{eq:a}\\
\nameeq{h(x) = ax^2+bx+c}{Quadratic}\label{eq:b}
\end{flalign}
  • Both this answer and Bernard's are excellent. I am choosing this since it was the first one provided. – summer Apr 28 '14 at 14:24
  • @summer Did you look at the question I suggested? The methods provided there are, in my opinion, better than those here. – egreg Apr 28 '14 at 15:55
  • @egreg, truth is that I missed your comment at first! Thanks for pointing out again and for the link, some interesting solutions there as well. I cannot believe I was struggling so much when there are so many possible ways to solve this issue! – summer Apr 28 '14 at 17:21
7

You can do that in a simpler way with the \flalign environment and the \llap command. Here is a code that shows two ways of doing it — centred with respect to the remaining white space or centredwith respect to line width:

    \documentclass{article}
    \usepackage{amsmath}

    \begin{document}
    Centring without taking the names into account:
    \begin{flalign}
     &  & f(x)  & = a &  & \text{\llap{Constant}}\label{eq:a} \\
     &  & h(x)  & = ax^2+bx+c  &  &  \text{\llap{Quadratic}} \label{eq:b}
    \end{flalign}

    Equations \eqref{eq:a} and \eqref{eq:b} look OK\dots

    \begin{flalign}
     &  & j(x)  & = \varinjlim_{C_j} &  & \text{\llap{Way too low!}} \label{eq:c}
    \end{flalign}

    \dots and the method doesn’t fail for Equation \eqref{eq:c}.\bigskip

    Other way to centre the main equations --- with respect to the remaining white space:

    \begin{flalign}
     &  & f(x)  & = a &  & \text{Constant}\label{eq:a’} \\
     &  & h(x)  & = ax^2+bx+c  &  &  \text{Quadratic}\label{eq:b’}
    \end{flalign}

    Equations \eqref{eq:a’} and \eqref{eq:b’} look OK\dots

    \begin{flalign}
     &  & j(x)  & = \varinjlim_{C_j} &  & \text{Way too low!} \label{eq:c’}
    \end{flalign}

    \end{document} 

enter image description here

Bernard
  • 271,350
  • This is a very intelligent answer of \llap indeed! Excellent answer as well. – summer Apr 28 '14 at 14:26
  • I forgot to mention that in case your "name" is actually a math formula, there is a \mathllap command defined in the essential mathtools package. – Bernard Apr 28 '14 at 14:52