4

Code

\documentclass[a4paper,twoside,12pt]{book}
\usepackage{amstext}
\usepackage[utf8]{inputenc}
\usepackage{cases}
\usepackage{amsmath}

\begin{document}
\begin{subnumcases}{}\label{eq:regola_scelta_reject}
    \begin{aligned}
    objective   &: \qquad \min \quad \sum_{j=1}^{H}x_jw_j\\
    subject to  &: \qquad \displaystyle\sum_{j=1}^{H}x_jw_j \geq W_L\\
    \end{aligned} \label{eq:regola_scelta_reject_1}\\
    \begin{aligned}
    objective   &: \qquad \min \quad \sum_{j=1}^{H}x_jw_j \vee H_{e} \geq 2 \\  
    subject to  &: \qquad \displaystyle\sum_{j=1}^{H}x_jw_j < W_L\\
    \end{aligned} \label{eq:regola_scelta_reject_2}\\
\end{subnumcases}
\end{document}

What I'm doing wrong? This is what I'm trying to acheive:

Example

gmeroni
  • 431
  • 3
    Please always post complete documents. Without effort it is hard to see what you have done wrong as we can't see the output or error message without reconstructing a document that you presumably have already. – David Carlisle Mar 13 '14 at 13:52
  • @DavidCarlisle Fixed. The fact is that casesrequest 2 condition on the same line. Is there any alternative to casesthat doesn't include the 2-nd condition? – gmeroni Mar 13 '14 at 13:59
  • surrounding the cases environment in dollar signs will remove the particular errors you are experiencing, but there are other issues, such as material you intend as text being placed into math style. – Steven B. Segletes Mar 13 '14 at 14:01
  • 1
    Also, when David suggests that "complete documents" should be posted, he means something that begins with \documentclass and ends with \end{document}. – Steven B. Segletes Mar 13 '14 at 14:02
  • @gmeroni as Steven says that isn't a usable document. – David Carlisle Mar 13 '14 at 14:12
  • cases is a math environment so put it inside \[....\] – David Carlisle Mar 13 '14 at 14:13
  • @StevenB.Segletes Ok. My request is how can i obtain this – gmeroni Mar 13 '14 at 14:15
  • It is called a MWE (minimum working example), and you are asked to construct it, so that we who are willing to help you don't have to guess as to what you might be trying to accomplish (TeX speaks louder than words). While some errors are straightforward, others are subtle and depend on an interaction of the various packages that are loaded, or what class you are using. Asking you to build an MWE may take a little of your time, but that is more polite and efficient than asking a multitude here to all build a version of your MWE ourselves, for your benefit. We have day jobs too. – Steven B. Segletes Mar 13 '14 at 14:19
  • @StevenB.Segletes The fact is: I font have a WORKING example...I don't know if I have to use subnumcases, cases, align, equino, ecc ecc...so I can't construct a MWE – gmeroni Mar 13 '14 at 14:21
  • Even if your MWE doesn't work, you can construct a small version "that doesn't work" that begins with \documentclass etc. An accompanying picture helps, preferably viewable in your question, rather than to a website that is blocked by my browser. – Steven B. Segletes Mar 13 '14 at 14:23
  • @StevenB.Segletes Initial question updated. – gmeroni Mar 13 '14 at 14:27
  • Indeed, that is now a real question. – Steven B. Segletes Mar 13 '14 at 14:28
  • @gmeroni you see in particular we would never have guessed you were loading the cases package (which I have never heard of) since cases is a standard amsmath command so any answers based on your original fragment would likely have been wrong – David Carlisle Mar 13 '14 at 15:06
  • not relevant to this question, but amsmath automatically loads amstext, so it's not necessary to load it separately. – barbara beeton Mar 13 '14 at 15:44

2 Answers2

5

enter image description here

\documentclass[a4paper,twoside,12pt]{book}
\usepackage{amstext}
\usepackage[utf8]{inputenc}


\usepackage{amsmath}
\usepackage{cases}

\begin{document}
\begin{subnumcases}{}\label{eq:regola_scelta_reject}
    \mbox{objective:}&$\displaystyle \qquad \min\sum_{j=1}^{H}x_jw_j$\\
    \mbox{subject to:}  &$\displaystyle \qquad \sum_{j=1}^{H}x_jw_j \geq W_L$\\[12pt]
     \xdef\theparentequation{\the\numexpr\theparentequation+1}%
     \setcounter{equation}{1}%
      \mbox{objective:}&$\displaystyle \qquad \min \sum_{j=1}^{H}x_jw_j \vee H_{e} \geq 2$ \\  
    \mbox{subject to:}  &$\displaystyle \qquad \sum_{j=1}^{H}x_jw_j < W_L$ \label{eq:regola_scelta_reject_2}
\end{subnumcases}
\end{document}
David Carlisle
  • 757,742
  • Is there a way to split in two part? I'd have (1a),(1b) and (2a),(2b) since I need to reference the two knapsack problem separately. – gmeroni Mar 13 '14 at 15:42
  • @gmeroni see update – David Carlisle Mar 13 '14 at 16:49
  • @DavidCarlisle: What comment are you replying to :) – Aditya Mar 13 '14 at 23:26
  • @DavidCarlisle Thanks but the outcome is this. I set the x.xx numbering. – gmeroni Mar 14 '14 at 08:33
  • @gmeroni The output of the code I posted above is as shown in the image I posted. If you have different input that isn't doing the right thing it is best to ask a new question with a complete document that demonstrates the problem. Not much I can do just looking at an image without knowing what made it. – David Carlisle Mar 14 '14 at 09:12
1

Maybe this code suits your needs – if I've well understood. You need the empheq package (which loads amsmath), with th overloadoption, to have a simpler code:

        \documentclass[a4paper]{article}
        \usepackage[utf8]{inputenc}
        \usepackage{mathtools}
        \usepackage[overload]{empheq}

        \begin{document}

        \begin{align}[left = (R)\enspace\empheqlbrace]%\label{eq:regola_scelta_reject}\smash[t]\smash[b]
         &  \begin{alignedat}{2}\label{eq:regola_scelta_reject_1}
          &  \text{objective: } & &  \min \sum_{j=1}^{H} x_j w_j\\
           & \text{subject to: } &\qquad   & \sum_{j=1}^{\smash H} x_j w_j \geq W_L\\
         \end{alignedat}\\]
            &   \begin{alignedat}{2} \label{eq:regola_scelta_reject_2}
          &  \text{objective: } & &  \min  \sum_{j=1}^{H}x_jw_j \vee H_{e} \geq 2 \\
           & \text{subject to: } & \qquad  & \sum_{j=1}^{\smash H} x_jw_j < W_L
         \end{alignedat}\
        \end{align}

        \end{document}

Results in: enter image description here

Note that you can't have a label for the align outer environment and for the inner alignedat environnments. I simulated a tag ((R)) for the outer align.

Bernard
  • 271,350
  • Thank you @bernard. Is there any way to label Objective and constraint separately like (1a) and (1b)? – gmeroni Mar 13 '14 at 15:21
  • 1
    In a simple way (I mean with pre-existing tools one just has to pick), I'm afraid not. The subequationsenvironment does that, but it does not work with nested environments like aligned and such. If I find something, I'll update my answer – Bernard Mar 13 '14 at 15:42
  • mathtools also loads amsmath. don't know whether this affects the [overload] option to empheq. – barbara beeton Mar 13 '14 at 15:46
  • @barbarabeeton: actually, empheq loads mathtools, hence amsmath. It's just that I used a minimal template that loads mathtools, and I forgot to cleanup my code on adding empheq. – Bernard Mar 13 '14 at 16:01