I have several tall, thin expressions - graphical diagrams - which I need to label as if they were equations. Given their shape, it would be mad to have them displayed one underneath the other. I really want to have them next to each other, and give them equation numbers displayed immediately underneath. How can I generate new equation numbers, and then typeset them wherever I please?

This is pseudocode for the sort of effect I want, where \newlabel{blah} is a fictional command which increments the equation count by 1, typesets (n) where n is the new equation number, and sets the label "blah" to refer to this new number.

\firstlongthinexpression & \secondlongthinexpression
\newlabel{firstexpr} & \newlabel{secondexpr}
In expressions~\eqref{firstexpr} and~\eqref{secondexpr}, we did blah blah blah.
  • Does it have to be in math mode? Since these or graphical diagrams, could you put them in a figure or even just a tabular, say? – Werner Aug 16 '11 at 17:02
  • Perhaps, but I don't think that changes the essence of the problem - I want a macro that generates new equation numbers associated to a particular label, and displays the number in-place. That's how I've set things up above. But if you see some better way to approach things given the context I've given, I'd be happy with that. – Jamie Vicary Aug 16 '11 at 17:08

You define your own commands \mylabel (which works with the existing equation counter) and \myref command to typeset both the label and the reference. In the code below I used \rule{<width>}{<height>} to produce a face "thin equation", just for reference.

\usepackage{array}% http://ctan.org/pkg/array

\newcommand*{\mylabel}[1]{% Label
  \refstepcounter{equation}% Correct increment for referencing and label
  \label{#1}% Label
  \textrm{(\theequation)}% Typeset label
\newcommand*{\myref}[1]{\textrm{(\ref{#1})}}% Reference


  E=mc^2 \label{einstein}

    \rule{5pt}{4em} & \rule{5pt}{3em} & \rule{5pt}{4em} & \rule{5pt}{3em} & \rule{5pt}{4em} \\
    \mylabel{firstexpr} & \mylabel{secondexpr} & \mylabel{thirdexpr} & \mylabel{fourthexpr} & \mylabel{fifthexpr}

In expressions~\myref{firstexpr} and~\myref{secondexpr}, we did blah blah blah. However, in expressions~\myref{fifthexpr}, 
\myref{fourthexpr} and \myref{thirdexpr} we have blah blah blah blah. I really like~\myref{einstein}.


Thin equations with counter/label/reference

Without any other specification, this works fine. However, if you use amsmath, a slight modification is required in the definitions of \mylabel and \myref:

\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\newcommand*{\mylabel}[1]{% Label
  \refstepcounter{equation}% Correct increment for referencing and label
  \ltx@label{#1}% Label
  \textrm{(\@currentlabel{})}% Typeset label
\newcommand*{\myref}[1]{\textrm{\eqref{#1}}}% Reference
  • Thanks Werner, that's delightful! But I will have other conventional equations in the document, so I really want to use the standard equation counter rather than a newly-declared one. Is this possible? – Jamie Vicary Aug 16 '11 at 20:41
  • @Jamie: I've updated my answer to use the conventional equation counter of the document. It will even work if you change the formatting of the equation number to say \renewcommand{\theequation}{\alph{equation}} for alphabetic equation numbers. – Werner Aug 16 '11 at 21:01
  • 1
    @Werner: your code won't work if the amsmath package is loaded; in this case, you'll need something like \makeatletter \newcommand*{\mylabel}[1]{ \refstepcounter{equation} (\@currentlabel{}) \ltx@label{#1} } \makeatother \newcommand*{\myref}[1]{\eqref{#1}} – Gonzalo Medina Aug 16 '11 at 21:26

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.