# Multiple labels in aligned environment

I would like to format an optimization problem by

\documentclass{article}
\usepackage{amsmath}

\begin{document}

We want to label each line separately. The inserted text and formulas
have to be aligned like in this example:
\begin{aligned} \label{eq:3} & \underset{X}{\text{minimize}} & & \mathrm{trace}(X) \\ & \text{subject to} && X_{ij} = M_{ij}, \; (i,j) \in \Omega, \\ & && X \succeq 0. \end{aligned}

\end{document}


(Already described in How to label an optimization problem with a label such as (P)?).

An ideal alignment of the inserted text and formulas is achieved by the aligned environment. However, I want to label each line separately. By placing \label{...} at each line

\begin{aligned} & \underset{X}{\text{minimize}} & & \mathrm{trace}(X) \label{eq:6}\\ & \text{subject to} && X_{ij} = M_{ij}, \; (i,j) \in \Omega, \label{eq:7} \\ & && X \succeq 0. \label{eq:9} \end{aligned}


I get the error message: "Package amsmath Error: Multiple \label's: label 'eq:4' will be lost."

How can I label each line individually?

• Using align environment instead of equation and aligned will work: \begin{align} & \max \sum p_t s_t \label{eq:3}\& \text{s.t. } s_t \leq d_t \label{eq:4}\& \sum s_t \leq I \label{eq:5} \end{align} – Peter Grill Mar 23 '13 at 9:14
• I need the tighter alignment provided by the aligned environment. The original example did not show the relevant point, so I inserted another example. – Robinaut Mar 23 '13 at 15:30

Only one label is possible within the equation environment. However, multiple labels are possible within an align environment. In your case, as in many other, using an align is preferable to using an aligned inside an equation. Moreover, the subequations environment lends itself well to your problem.

Additional note: in math mode, it's good practice to put a thin space (\,) before punctuation marks (such as full stops and commas), so that the reader does not confuse them as part of the math quantities they precede.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

We want to label each line separately. The inserted text and formulas
have to be aligned like in this example:
\begin{subequations}
\label{eq:optim}
\begin{align}
\underset{X}{\text{minimize}}

• There is another approach with alignat which is more closely to the origonal formatting: \begin{alignat}{2} &\underset{X}{\text{minimize}} \quad& &\mathrm{trace}(X) \label{eq:cost}\ &\text{subject to} & &X_{ij} = M_{ij}\,, \; (i,j) \in \Omega\,, \label{eq:const1}\ & & &X \succeq 0 \,. \label{eq:const2} \end{alignat} – Robinaut Mar 24 '13 at 9:49