3

I want to have the following output .

enter image description here

For this purpose , I have the following code .

\begin{align*}
                    Maximize     \mathbf{z = x_1+2x_2+3x_3}  
                                 \end{align*}
                             
                \begin{align*} 
                    Subject to  \mathbf{x_1 + \hspace{2cm}+2x_3 \leq 2  }\\
                                    \mathbf{ \hspace{2cm}x_2+2x_3 \leq 2 } \\   
                                    \mathbf{x_1  \geq 0 , x_2 \geq 0 , x_3 \geq 0}  
                             \end{align*}  

For this code , I have the following output :

enter image description here

I do not understand how to achieve my desired output . What have I to do ? Please help me .

4
  • Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – user31729
    Commented Jun 18, 2014 at 13:51
  • 1st question , Why the vertical space is so high between Maximize and "Subject To" line ? Commented Jun 18, 2014 at 13:54
  • That vertical space is controlled by code you have not shown please post a complete small document that produces the image shown. Commented Jun 18, 2014 at 13:55
  • 1
    Personal question: Why do you want this kind of strange output?
    – Johannes_B
    Commented Jun 18, 2014 at 13:59

2 Answers 2

3

I would rather suggest to reverse the first equation and align them or remove the text from the math alignment environment, making to alignments

\documentclass{article}
\usepackage{amsmath}


\boldmath

\begin{document}
\begin{align*}
 \text{Maximize\phantom{o}}   &&              x_1+2x_2+3x_3 &=  z    \\
 \text{Subject to} &&     x_1+ 2x_3 &  \leq 2 \\
                   &&      x_2+2x_3 &  \leq 2  \\   
                   && x_1  \geq 0 , x_2 \geq 0 , x_3 &\geq 0
\end{align*}  


Maximize
\begin{align*}
    &&              z &= x_1+2x_2+3x_3 
\end{align*}
subject to 
\begin{align*}
 &&     x_1+ 2x_3 &  \leq 2 \\
 &&      x_2+2x_3 &  \leq 2  \\   
 && x_1  \geq 0 , x_2 \geq 0 , x_3 &\geq 0
\end{align*}  

\end{document}

enter image description here

1
  • since you're using amsmath, using \intertext (and staying within a single align*) for "subject to" would result in better vertical spacing in your second example. Commented Jun 18, 2014 at 14:15
6

I would suggest you not use bold for the math terms: Rendering so much material in bold tends to make it look excessively heavy without enhancing the readability or intelligibility of what's being presented. I would use a common gather* environment for the four lines of display math, the shortintertext macro (provided by the mathtools package, which also loads the amsmath package), and a coupld of \phantom statements to help arrange the desired spacing on the first two lines follow "subject to".

enter image description here

\documentclass{article}
\usepackage{mathtools}
\setlength\textwidth{4in} % just for this example
\begin{document}
\noindent
Let us consider the following problem.
\begin{gather*}
\text{Maximize } z = x_1+2x_2+3x_3
\shortintertext{subject to}
x_1 \phantom{+x_2} +2x_3 \leq 2  \\
\phantom{x_1+}x_2+2x_3 \leq 2 \\
x_1  \geq 0 ,\quad x_2 \geq 0 , \quad x_3 \geq 0
\end{gather*}  
\end{document}

Personally, I prefer the look without the \phantom statements; see, e.g., Christian Hupfer's proposed solution.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .