12

I want to write my linear program so that it looks like in this picture: integer program

meaning I want to have the following:

  • text aligned to the left
  • all the x_{j} variables to be one another
  • the i= and j= statement to be again to be one under the other

This is what I have so far:

\begin{equation}
\begin{split}
\text{minimize} \displaystyle\sum\limits_{j=1}^{m} w_{j}*&x_{j} \\
\text{subject to} \displaystyle\sum\limits_{j:e_{i} \in S_{j}} &x_{j} \geq 1, i=1 ,..., n\\
                                         &x_{j} \in \{0,1\}, j=1 ,..., m
\end{split}
\end{equation}

I tried using multiple &s, but either I use them and nothing changes, or I get the following error: Extra alingment tab has been changed to \cr \end{split}. I have searched this error and I know that it appeares if I forget to write a & or I have an extra one, but this is not my case. This is the code:

\begin{equation}
\begin{split}
&\text{minimize} \displaystyle\sum\limits_{j=1}^{m} w_{j}*&x_{j} & \\
&\text{subject to} \displaystyle\sum\limits_{j:e_{i} \in S_{j}} &x_{j} \geq 1, &i=1 ,..., n\\
&                                             &x_{j} \in \{0,1\}, &j=1 ,..., m
\end{split}
\end{equation}

How can I align them in the way that I want?

And also is it possible to do it without align? Because this program is at the end of my page and if I use align it gets placed on the next page and I don't want that.

  • I find no reason for having x_{j} aligned horizontally. – egreg Jun 15 '14 at 13:39
  • How do you think it should be aligned? – Jessy09 Jun 15 '14 at 14:42
  • I think it should be aligned to the left with the summation; what if the first condition were \sum a_jx_j? Would you align the x_j? – egreg Jun 15 '14 at 14:45
  • So you're saying that in the second line x_j should be next to the sum? And only the x_j in the 2nd and 3rd line should be one under the other, right? If yes, that's how they are aligned in the second answer. – Jessy09 Jun 15 '14 at 14:55
11

Something like this. Use of array

enter image description here

Code

\documentclass[a4paper]{article}
\usepackage[paper size={10cm,5cm}]{geometry}
\pagestyle{empty}
\usepackage{amsmath,amssymb}
\begin{document}
\begin{equation*}
\begin{array}{ll@{}ll}
\text{minimize}  & \displaystyle\sum\limits_{j=1}^{m} w_{j}&x_{j} &\\
\text{subject to}& \displaystyle\sum\limits_{j:e_{i} \in S_{j}}   &x_{j} \geq 1,  &i=1 ,..., n\\
                 &                                                &x_{j} \in \{0,1\}, &j=1 ,..., m
\end{array}
\end{equation*}
\end{document}
11

The = signs are not quite vertically aligned. Here is a solution with alignat* that gives a correct alignment, and has a somewhat simpler syntax. I also propose a variant, where the sums are aligned, and the x_j are only partially aligned, that look better in my opinion:

\documentclass[a4paper]{article}
\usepackage[paper size={10cm,5cm}]{geometry}
\pagestyle{empty}
\usepackage{mathtools,amssymb}

\begin{document}

\begin{alignat*}{3}
 & \text{minimize} & ∑_{j=1}^{m} w_{j}x_{j}& \\
 & \text{subject to} \quad& ∑_{\mathclap{{j:e_{i} ∈ S_{j}}}}x_{j}& \geq 1, & i &=1 ,..., n\\
                 && x_{j}& ∈ \{0,1\},\quad & j &=1 ,..., m
\end{alignat*}

\begin{alignat*}{2}
  & \text{minimize: } & & ∑_{j=1}^{m} w_{j}x_{j} \\
   & \text{subject to: }& \quad & ∑_{\mathclap{{j:e_{i} ∈ S_{j}}}}\begin{aligned}[t]
                    x_{j} & \geq 1,& i & =1, \dots, n\\[3ex]
                  x_{j} & ∈ \{0,1\}, & \quad j &=1 ,\dots, m
                \end{aligned}
\end{alignat*}

\end{document} 

enter image description here

Variant: enter image description here

  • You can use \mathclap for j:e_{i} \in S_{j}}. – user11232 Jun 15 '14 at 13:16
  • @HarishKumar: Judicious remark. I've modified my code, but had to move the &x_j alignment point to & \geq (and similarly &\in). – Bernard Jun 15 '14 at 13:37
  • @HarishKumar: But if the Σ's align, there will be a gap between Σ and x_j in the second line! Or I didn't grasp well what you mean? – Bernard Jun 15 '14 at 13:52
  • @HarishKumar: Personally I would have aligned the Σ's and only the x_j's in the last two lines. But so required th O.P… – Bernard Jun 15 '14 at 13:55
  • @Bernard: When I wrote the question I didn't think about the \sum being aligned, I only wanted the text and the i= and j= to be aligned. But thank you for your response and I will consider aligning the \sum as well. – Jessy09 Jun 15 '14 at 14:40

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.