Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am wondering if it is possible (and if so how) to add names to equations just underneath the equation number. I am just using the standard equation environment to display the equation centered in the middle of the page, with the equation number flushed to the right hand side. I need to put some text immediately below the equation number to serve as the equation's name. Other requirements include:

  • The text should be horizontally right-aligned with the equation number and should not affect the latter's vertical alignment with the equation; i.e. the equation and equation number should still be vertically in line with each other.
  • The vertical spacing between the equation number and name should be standard text spacing; i.e. if the equation is vertically tall, there should not be excess space between the equation number and name.
  • The text should be able to be formatted in different font styles. Right now, I need to format it in \sf.

Here is a MWE (without the equation name):

\documentclass{article}
\usepackage{amsmath}

\numberwithin{equation}{section}

\begin{document}

\section{First Section}
\label{sec:section1}
\begin{equation}
\label{eqn:label}
    \boxed{M\approx\frac{\pi}{4}\left(\frac{2d}{\lambda_o}\right)^2\left(\mathrm{NA}\right)^2}
\end{equation}

Reference \eqref{eqn:label}.

\end{document}

Here is a snapshot example of what I'd like to achieve (taken from Saleh, 2007):
Equation with name under number

I have tried using the \tag command, but realized that this not only replaces the equation number, which I do not want, but also causes the equation number counter to skip that particular equation. Ideally, the equation should still function as a regular numbered equation, that can be number-referenced (via \eqref or other), but with the addition of some text below the equation number.

Any help will be much appreciated.

share|improve this question
    
Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. –  barbara beeton Aug 13 '13 at 16:25
    
does this text have to be entered as part of the displayed equation? would you be willing to consider a separate line, flushed right, immediately following the numbered display? –  barbara beeton Aug 13 '13 at 16:27
    
@barbara, Thanks for the welcome. I have added a picture example that should make it clearer. The text should be on the next line of the equation number, but still within the general "space" of the equation. I suppose then that it should be part of the equation. –  Nicholas Wong Aug 13 '13 at 19:08
    

3 Answers 3

Here's an easy by using the starred version of \tag from amsmath:

enter image description here

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\newcommand{\eqname}[1]{\tag*{#1}}% Tag equation with name
\begin{document}

\begin{align}
  f(x) &= a \\ \eqname{Constant} \\
  g(x) &= ax \\ \eqname{Linear} \\
  h(x) &= ax^2+bx+c \label{abc} \\ \eqname{Quadratic}
\end{align}
See~\eqref{abc}.
\end{document}

For consistency, I've wrapped \tag* inside \eqname.


Depending on your equation construction, you can adjust the vertical skip between the equation and the name:

enter image description here

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\newcommand{\eqname}[1]{\tag*{#1}}% Tag equation with name
\begin{document}

\begin{align}
  \boxed{M \approx \frac{\pi}{4}\biggr(\frac{2d}{\lambda_0}\biggr)^2(\text{NA})^2} \label{abc} \\[-\baselineskip]
  \eqname{Number of TE Modes}
\end{align}
See~\eqref{abc}.
\end{document}

Here I've moved it up by \baselineskip, but you can adjust this to your liking.

share|improve this answer
    
Thank you for this solution. Admittedly, it is a very clean solution. However, because of the line break, the space between the equation number and equation name will get large if the equation is tall. Sorry I did not mention this requirement earlier, but it has since been edited into my original question. As can be seen in the image example I added, the equation name should take its "next line" reference from the equation number and not the equation itself. Also, it does not seem to work with the equation environment, in which case, only the eqname is shown without the equation number. –  Nicholas Wong Aug 13 '13 at 18:34
    
@NicholasWong: See the update at the end of my answer. –  Werner Aug 13 '13 at 18:38

The following example hacks into the internals of package amsmath to add the equation name at the stage, where the equation tag is set in the displayed equation.

  • \eqname{<name of the equation>} sets the equation name. The name increases the depth of the equation tag, thus the base line of the equation number does not change.

  • The width of the equation name decreases the space that is available for the equation. Thus the equation number might be moved down (feature of amsmath) as shown in equation 5 of the example.

    The star form \eqname* ignores the width of the equation name. It can be used, if it is clear, that the equation name does not collide with the contents of the equation, see equation 6 of the example.

  • Package nameref is supported to reference the name of the equation. The label name is given in the optional argument. (The example uses package nameref, but the package is not required.)

  • The formatting of the equation name can be changed by redefining \eqnameref. The example uses \textsf as requested in the comment.

Example:

\documentclass[a5paper]{article}
\usepackage{amsmath}
\usepackage{nameref}

\newcommand*{\eqnameformat}[1]{%
  \textsf{#1}%
}

\makeatletter
\@ifdefinable{\org@maketag@@@}{%
  \let\org@maketag@@@\maketag@@@
  \renewcommand*{\maketag@@@}[1]{%
    \org@maketag@@@{%
      \@ifundefined{eq@name}{#1}{%
        \begin{tabular}[t]{@{}r@{}}%
          #1\tabularnewline
          \eqnameformat{\@nameuse{eq@name}}%
        \end{tabular}%
      }%
    }%
  }%
}
\newif\ifeqname@star
\newcommand*{\eqname}{%
  \@ifstar{\eqname@startrue\eqname@}{\eqname@starfalse\eqname@}%
}
\newcommand*{\eqname@}[2][]{%
  \gdef\eq@name{#1}%
  \ifx\eq@name\@empty
  \else
    \begingroup
      \@ifundefined{GetTitleString}{%
        \gdef\@currenteqlabelname{#2}%
      }{%
        \GetTitleString{#2}%
        \global\let\@currenteqlabelname\GetTitleStringResult
      }%
      \let\@currentlabelname\@currenteqlabelname
      \label{#1}%
    \endgroup
  \fi
  %
  \gdef\eq@name{#2}%
  \ifx\eq@name\@empty
    \global\let\eq@name\relax
  \else
    \ifeqname@star
      \gdef\eq@name{\llap{#2}}%
    \fi
  \fi
}
\@ifdefinable{\org@make@display@tag}{%
  \let\org@make@display@tag\make@display@tag
  \def\make@display@tag{%
    \@ifundefined{@currenteqlabelname}{}{%
      \let\@currentlabelname\@currenteqlabelname
    }%
    \org@make@display@tag
  }%
}
\let\eq@name\relax
\let\@currenteqlabelname\relax
\g@addto@macro\displ@y@{%
  \global\let\eq@name\relax
  \global\let\@currenteqlabelname\relax
}
\@ifdefinable{\org@math@cr@@}{%
  \let\org@math@cr@@\math@cr@@
  \def\math@cr@@[#1]{%
    \org@math@cr@@[{#1}]%
    \noalign{%
      \global\let\eq@name\relax
    }%
  }%
}
\@ifdefinable{\org@eqref}{%
  \let\org@eqref\eqref
  \renewcommand*{\eqref}[1]{%
    \begingroup
      \let\eq@name\relax
      \org@eqref{#1}%
    \endgroup
  }%
}
\g@addto@macro\equation{%
  \eqname{}%
}
\makeatother

\begin{document}

% some test cases

The first equation \eqref{eq:einstein} with  name ``\nameref{eq:einstein}'',
the second equation \eqref{eq:second} and
and the last equation \eqref{eq:last}  with name ``\nameref{eq:last}''.

\begin{gather}
\eqname[eq:einstein]{Einstein}
E=mc^2\\
\label{eq:second}
a=b
\end{gather}

\begin{equation}
\eqname{Name AB}
a=b
\end{equation}

\begin{gather}
x=y
\end{gather}

\begin{gather}
\eqname{A longer equation name A/no star}
a=b=c=d=e=f=g=h=i=j\\
\eqname*[eq:last]{A longer equation name B/star}
a=b=c=d=e=f=g=h=i=j
\end{gather}
\end{document}

Result

share|improve this answer
    
This is a good solution, thank you. However, it seems that the \eqref referencing only works well with the gather environment, whereas if I use it for an equation from an equation environment, the eqname gets displayed below the equation number, similar to the problems mentioned in the comments to the previous solutions. –  Nicholas Wong Aug 14 '13 at 12:34
    
@NicholasWong: I can reproduce it, if \eqref is used inside an equation. Thus I have updated the answer to fix this issue for \eqref. –  Heiko Oberdiek Aug 14 '13 at 15:20
    
Thank you, it works now. There is another issue however. I tried the align environment with multiple equation lines and it works with your code. Now I want to box all the equations, have each equation numbered, and place the eqname underneath the last equation number. I tried out the empheq package and its \begin{empheq}[box=\fbox]{align}...\end{empheq} suggestion. Everything compiles well, but in the output, the equation numbers are not quite vertically aligned to their respective equations. The alignment is fine without the eqname at the end. –  Nicholas Wong Aug 14 '13 at 19:09
    
By the way, I just noticed that if I use \eqname in an equation environment, and then have a subsequent equation without \eqname but just the usual \label, then the equation name of the first equation gets displayed underneath the second equation's number as well. –  Nicholas Wong Aug 14 '13 at 19:14
    
@NicholasWong: Unnamed equation fixed. –  Heiko Oberdiek Aug 14 '13 at 20:14

Here's a solution. I introduce the environment Nequation to mean "named equation," in which the name is passed as an argument. I show how it does not screw up the use of equation environment's numbering scheme. [EDITED to fix referencing by label, and to add sections to eq #, and also to allow text formatting to name, per user request]

In response to the user's latest query, sub and sub-sub sections can be added where I first \renewcommand\theequation{\thesection.\arabic{equation}}. Text formatting can come in one of two ways. It can be made to happen for every label, as I have done with \small in the Nequation environment, or it can be done on a label-by-label basis, as I show with \textsf in the actual invocation line.

\documentclass{article}
\usepackage{amsmath}
\usepackage{stackengine}
\def\stackalignment{r}
\def\useanchorwidth{T}
\def\stacktype{L}
\newlength\eqshift
\setlength\eqshift{\widthof{)}}
\renewcommand\theequation{\thesection.\arabic{equation}}
\let\savetheequation\theequation
\newenvironment{Nequation}[1]{%
  \def\thecurrentname{#1}%
  \let\theequation\savetheequation%
  \begin{equation}%
  \renewcommand\theequation{%
    \stackunder{\savetheequation}%
    {{\small\thecurrentname}\hspace{-\the\eqshift}}}%
}{%
  \end{equation}%
  \let\theequation\savetheequation%
  \ignorespacesafterend%
}
\begin{document}
\section{New Section}
\begin{Nequation}{\textsf{Equation Name}}
  \label{eqn:label}
    y=mx+c
\end{Nequation}
We find in equation~\eqref{eqn:label}, a different result than
\begin{equation}
    \label{eqtwo}
    y=mx^2+c
\end{equation}
However, in equation~\eqref{eqtwo}\ldots
\end{document}

enter image description here

share|improve this answer
    
Thank you for your solution. Yes this is what I was after. However, there are some problems. Firstly, the equation name gets displayed together with the number when I reference the equation using \eqref. I need just the equation number to be displayed as how we usually reference equations. Secondly, while the equation counter is correct, it does not display the section/subsection enumeration, and trying \numberwithin{Nequation}{section} did not work. –  Nicholas Wong Aug 13 '13 at 17:09
    
@NicholasWong I'll give some thought to the label issue. However, it would help if you, in your question, posted a complete MWE (minimum working example), since it is likely you are not using the article class if you have things like section/subsection enumeration. We can't know such things unless you tell us in your question. –  Steven B. Segletes Aug 13 '13 at 17:13
    
Sorry, I am still new to this. Thanks for the edit. Actually for the section enumeration problem, I tried running your MWE with the article class. I just added the amsmath package and used the \numberwithin command, but only the equation from the regular equation environment has its number displayed with the section numbering. –  Nicholas Wong Aug 13 '13 at 17:47
    
It looks quite good now, though is there any way to make this scalable to subsection, subsubsection, etc.? I am trying (rather slowly) to understand your code, and I am guessing it has something to do with the \thesection command. Also, and I really apologize for not making this clear earlier, it would be good if I can format the text within the Equation Name field. Right now, I am using \sf formatting, but I hope to be able to do other formatting in future use. Currently, adding any formatting produces an "Undefined control sequence" error. –  Nicholas Wong Aug 13 '13 at 18:55
    
@StevenB.Segletes Thank you for the updates. –  Nicholas Wong Aug 14 '13 at 12:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.