# Adding equation numbers to aligned environment

I need to typeset a text with several equations that: (#1) have to include the "maximize" and "subjet to" expressones in line with the corresponding equations; (#2) have to include three aligned right braces ; and (#3) the equations must be individually numbered.

After trying several routes (using optidef, rcases, plain arrays...) I found a clue in Align multiple equations within right braces

I've solved problem #2, and I've dealt with problem #1 by brute force, but I have no idea of how to solve requirement #3 (equation numbers).

\documentclass{memoir}
\usepackage{amsmath}
\usepackage{lipsum}
% ================================================
\begin{document}
%
\lipsum[1][1-5]
%
\begin{aligned} \text{Maximize:}\qquad\qquad W &= W ( U_1 , U_2 ) \\[\jot] \text{Subject to:}\qquad\qquad U_1 &= U_1 \left( x_1 , y_1 \right)\\ U_2 &= U_2 \left( x_2 , y_2 \right)\\[2\jot] x &= x \left( K_x , L_x \right)\\ y &= y \left( K_y , L_y \right)\\[2\jot] K_x &+ K_y = \overline{K} \\ L_x &+ L_y = \overline{L} \end{aligned} \begin{aligned} &\left.\vphantom{\begin{aligned} \text{Maximize:}\qquad\qquad W &= W ( U_1 , U_2 )\\[\jot] \end{aligned}}\right.\\ &\left.\vphantom{\begin{aligned} \text{Subject to:}\qquad\qquad U_1 &= U_1 \left( x_1 , y_1 \right)\\ U_2 &= U_2 \left( x_2 , y_2 \right)\\[2\jot] \end{aligned}}\right\rbrace\quad\text{Preferences}\\ &\left.\vphantom{\begin{aligned} x &= x \left( K_x , L_x \right)\\ y &= y \left( K_y , L_y \right)\\[2\jot] \end{aligned}}\right\rbrace\quad\text{Tecnology}\\ &\left.\vphantom{\begin{aligned} K_x &+ K_y = \overline{K} \\ L_x &+ L_y = \overline{L} \end{aligned}}\right\rbrace\quad\text{Resources}\\ \end{aligned}
%
\lipsum[1][1-5]
%
\end{document}


Which gives this output:

Any hint will be welcome.

• Welcome to tex.sx. The equation environment will only ever apply a single equation number to the whole group. You have already started to segment the structure using the sub-environment aligned. Replace equation by gather (an environment provided by amsmath) and a separate number will be assigned to each of the aligned groups immediately below gather. You'll have to break this up a little more, but the approach should be straightforward. Mar 23, 2021 at 2:57
• @barbarabeeton Thank you for your feedback. I have tried several combinations of gather and aligned, with no success, though, I am unable to see the route I should follow. Could you elaborate a little bit? Many thanks Mar 23, 2021 at 15:39

## 2 Answers

You could overlap the 2 row entries using \raisebox. (This is how multirow works, more or less.)

If you want to move Maximize all the way to the left, replace align with flalign and add an extra & to the right.

\documentclass{memoir}
\usepackage{amsmath}
\usepackage{lipsum}

\newsavebox{\tempbox}
% ================================================
\begin{document}
%
\lipsum[1][1-5]
%
\savebox{\tempbox}{\displaystyle \left. \begin{aligned} \mathstrut\\ \mathstrut\end{aligned}\right\rbrace}%
%
\begin{align}
&\text{Maximize:}&        W &= W ( U_1 , U_2 )\\[\jot]
&\text{Subject to:}&      U_1 &= U_1 \left( x_1 , y_1 \right)  && \raisebox{-0.5\baselineskip}[0pt][0pt]{\usebox\tempbox Preferences}\\
&&                        U_2 &= U_2 \left( x_2 , y_2 \right)\\[2\jot]
&&                        x &= x \left( K_x , L_x \right) && \raisebox{-0.5\baselineskip}[0pt][0pt]{\usebox\tempbox Technology}\\
&&                        y &= y \left( K_y , L_y \right)\\[2\jot]
&&                        K_x &+ K_y = \overline{K} && \raisebox{-0.5\baselineskip}[0pt][0pt]{\usebox\tempbox Resources}\\
&&                        L_x &+ L_y = \overline{L}
\end{align}
%
\lipsum[1][1-5]
%
\end{document}


• That's exactly what I need. Thanks a lot. Mar 23, 2021 at 23:23

Speaking for myself, I find that a layout with lots of curly braces runs the serious risk of chopping up the visual "flow" of the elements in the multi-line equations, making the material more difficult rather than easier to grasp.

I would therefore like to propose two entirely different layouts for your consideration. As a side-effect of rearranging the material, numbering the equations is trivially easy.

The horizontal lines in the following screenshot are there just to delimit the vertical extent of the alignat and equation/alignat groups. Still speaking for myself, I find the second layout simpler and therefore more attractive.

\documentclass{memoir}
\usepackage{amsmath}
\begin{document}
\hrule
\begin{alignat}{3}
\text{Maximize}&\qquad&               &&          W &= W(U_1,U_2) \\[2\jot]
\text{Subject to}&&\text{Preferences}&\qquad&   U_1 &= U_1( x_1,y_1)\\
&&&&                          U_2 &= U_2( x_2,y_2)\\[\jot]
&&\text{Technology} &&          x &= x (K_x,L_x )\\
&&&&                            y &= y (K_y,L_y )\\[\jot]
&&\text{Resources} &&         K_x &+ K_y = \bar{K} \\
&&&&                          L_x &+ L_y = \bar{L}
\end{alignat}
\hrule

$$\text{Maximize} \quad W = W(U_1,U_2)$$
subject to the following conditions:
\begin{alignat}{2}
\text{Preferences}&\qquad&   U_1 &= U_1( x_1,y_1)\\
&&         U_2 &= U_2( x_2,y_2)\\[\jot]
\text{Technology} &&           x &= x (K_x,L_x )\\
&&           y &= y (K_y,L_y )\\[\jot]
\text{Resources}  &&         K_x &+ K_y = \bar{K} \\
&&         L_x &+ L_y = \bar{L}
\end{alignat}
\hrule
\end{document}

• The thing here is that I'd like to follow, as much as possible, the original layout. No doubt that yours are good alternatives. Thank you Mar 23, 2021 at 17:12