4

I am trying to write an optimization problem in my document, and for convenience, to define a label to refer to it. I don't want to refer to it as equation (3), which I know how to do, I want to define a special text label for it, see below for an example.

       max  \sum p_t s_t
(P)    s.t. s_t \leq d_t
            \sum s_t \leq I

Is there a way to put the label on the right side if I so desire? For example,

max  \sum p_t s_t
s.t. s_t \leq d_t    (P)
\sum s_t \leq I
N.N.
  • 36,163
  • The first part of your question is answered in http://tex.stackexchange.com/questions/12026/label-equation-with-a-symbol – Caramdir Aug 08 '11 at 20:55
  • I think the labels are on the right by default. Are you doing something to make them go to the left? – Caramdir Aug 08 '11 at 20:57
  • 1
    @Caramdir: Yes, they are on the right by default. Setting them to the left can by done by the leqno package option: \usepackage[leqno]{amsmath}. But that will then hold for all equations. – Werner Aug 08 '11 at 21:00
  • 1
    \[ f(x) = y \eqno{(P)} \] will put (P) on the right even with leqno, but it's not a true tag, and can't be referred back to with \ref (AFAIK). – frabjous Aug 08 '11 at 22:42
  • Thank you for your answers! That definitely answers my questions. – I Like to Code Aug 10 '11 at 19:10

2 Answers2

5

this will give you the tag and xref you want. you'll probably want to adjust the alignment, but that's not what the question was about.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

We want to refer to an optimization problem \eqref{opt-P} with a
non-numeric tag.
\begin{equation}
\begin{aligned}
& \max \sum p_t s_t\\
& \text{s.t. } s_t \leq d_t\\
& \sum s_t \leq I
\end{aligned}
\tag{P}\label{opt-P}
\end{equation}

\end{document}

if you're using amsmath (as this example does) and the tags are usually on the left, then add this to the preamble:

\makeatletter
\newcommand{\onetagright}{\tagsleft@false}
\makeatother

wrap the equation in \begingroup \onetagright ... \endgroup and just that one tag goes on the right.

David Carlisle
  • 757,742
3

\[ f(x) = y \eqno{(P)} \] will put (P) on the right even with leqno, but it's not a true tag, and can't be referred back to with \ref (AFAIK).

frabjous
  • 41,473
  • I'm out of votes, but your answer will receive an upvote tomorrow. – lockstep Sep 04 '11 at 22:15
  • The braces should be unnecessary, as everything from \eqno to the first $ (with expansion, so \] will end it) is the "equation number" and it's definitely not a command with an argument. Maybe \eqno\textup{(P)} would be better, since the equation number is typeset in math mode. – egreg Sep 04 '11 at 23:47