3

I am trying to write an optimization problem like below using eqnarray:

Max   z =a + b   (1)
s.t   a > 1     
      b < 4     

But I want to write the sub-equation numbers as (1.a) and (1.b) like below:

Max   z =a + b   (1)
s.t   a > 1      (1.a)
      b < 4      (1.b)

How can I write it? please help.

5

It's easy with alignat, using \tag for suppressing the advancement of the numbering and setting the referenced equation number instead.

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{subequations}\label{eq:foo}
\begin{alignat}{2}
\max        &\quad& z &= a + b   \tag{\ref{eq:foo}} \\
\text{s.t.} &     & a &> 1 \\
            &     & b &< 4
\end{alignat}
\end{subequations}

\end{document}

You can of course add labels also for the two conditions.

enter image description here

1
  • i picked this answer as this looks easy for me. thanks @egreg – jhon_wick Sep 3 '15 at 20:33
3

First off: Don't use eqnarray. It's badly deprecated. Use one of the multi-line equation environments of the amsmath package instead.

If your formatting need is one-off, it's probably not worth the overhead to set up a separate environment. Instead, simply use \tag and \ref directives.

enter image description here

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{gather}
\max   z =a + b   \label{eq:1} \\
\text{s.t.}\quad           a > 1     \tag{\ref{eq:1}a} \\
\phantom{\text{s.t.}}\quad b < 4     \tag{\ref{eq:1}b} 
\end{gather}
\end{document}

If you need to use this more than once, you may wish to use combined equation (for the main equation) and gather or align (for the conditions) environments. (The advantage of combining these environments is that LaTeX will, if need be, find a good pagebreak.) E.g.,

enter image description here

\documentclass{article}
\usepackage{amsmath}
\newcommand\ajustspaceandequationnumber{%
   \vspace{-\belowdisplayskip}
   \vspace{-\abovedisplayskip}
   \addtocounter{equation}{-1}}
\begin{document}
\begin{equation}
\max   z =a + b  
\end{equation}
\ajustspaceandequationnumber
\begin{subequations}
\begin{align}
\text{s.t.}\quad  &a > 1   \\
 & b < 4     
\end{align}
\end{subequations}
\end{document}
1
  • thanks for the advice regarding eqnarray and ur answer @Mico. – jhon_wick Sep 3 '15 at 20:33

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.