2

I am trying to convert a linear program into standard form, but I can't use & to make the equality sign and inequality sign in the same column. The following gives some error if I try to add more &.

\documentclass[12pt]{article}
\begin{document}
\begin{eqnarray*}
&\min & x_1+3x_2-5x_3+2x_4-7x_5\\
&s.t. & 3x_2-8x_4+x_5=15\\
&&4x_1-8x_2+2x_4+x_5=25\\
&&x_1+8x_2-5x_4-29\geq 0\\
&&-2x_1-5x_2-5x_3+3x_5+27\geq 0\\
&&x_2, x_4 \geq 0\\
&&-x_5\geq 0
\end{eqnarray*}
\end{document}
3
  • 6
    See eqnarray vs align before going any further...
    – Werner
    Commented Jan 15, 2018 at 21:28
  • 1
    welcome to tex.sx. do follow @Werner's recommendation. Commented Jan 15, 2018 at 21:33
  • 1
    if you do use eqnarray (which is not advised) then you have all the & in the wrong place, they should be around the operator so x_1+8x_2-5x_4-29 &\geq& 0\\ and same on every other line, so that you get a central column with all the operators aligned. Commented Jan 15, 2018 at 21:35

3 Answers 3

2

I suppose you want the first solution, but I think the second solution looks nicer:

\documentclass[12pt]{article}
\usepackage{amsmath}

\begin{document}

\begin{align*}
\min {}&x_1+3x_2-5x_3+2x_4-7x_5\\
\textup{ s.t.} & \begin{aligned}[t] 3x_2-8x_4+x_5 & =15\\
4x_1-8x_2+2x_4+x_5 & =25\\
x_1+8x_2-5x_4-29 & \geq 0\\
-2x_1-5x_2-5x_3+3x_5+27 & \geq 0\\
x_2, x_4 & \geq 0\\
-x_5 & \geq 0
\end{aligned}
\end{align*}
\begin{align*}
\min {}&x_1+3x_2-5x_3+2x_4-7x_5\\[1ex] \textup{ s.t.} &\enspace \begin{array}[t] {|l} 3x_2-8x_4+x_5 =15\\
 4x_1-8x_2+2x_4+x_5 =25\\
 x_1+8x_2-5x_4-29 \geq 0\\
 -2x_1-5x_2-5x_3+3x_5+27 \geq 0\\
 x_2, x_4 \geq 0\\
 -x_5 \geq 0
\end{array}
\end{align*}

\end{document} 

enter image description here

1

I’m not sure I’ve understood what you want: see if this can do.

Output of the following code

This output is generated by the following code:

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly 
                                 % declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.

\usepackage{amsmath}



\begin{document}

Text before the equation.
\begin{alignat*}{1}
    \min\quad & x_1+3x_2-5x_3+2x_4-7x_5 \\
    \text{s.t.}\quad &
        \begin{aligned}[t]
            3x_2-8x_4+x_5 &= 15\\
            4x_1-8x_2+2x_4+x_5 &= 25\\
            x_1+8x_2-5x_4-29 &\geq 0\\
            -2x_1-5x_2-5x_3+3x_5+27 &\geq 0\\
            x_2, x_4 &\geq 0\\
            -x_5 &\geq 0
        \end{aligned}
\end{alignat*}  
Text after the equation.

\end{document}

Still another possibility:

Output of the second code sample

The code:

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly 
                                 % declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.

\usepackage{amsmath}



\begin{document}

Text before the equation.
\begin{alignat*}{1}
    \min\quad & x_1+3x_2-5x_3+2x_4-7x_5 \\
    \text{s.t.}\quad &
        \left\{
            \begin{aligned}
                3x_2-8x_4+x_5 &= 15\\
                4x_1-8x_2+2x_4+x_5 &= 25\\
                x_1+8x_2-5x_4-29 &\geq 0\\
                -2x_1-5x_2-5x_3+3x_5+27 &\geq 0\\
                x_2, x_4 &\geq 0\\
                -x_5 &\geq 0
            \end{aligned}
        \right.
\end{alignat*}  
Text after the equation.

\end{document}
0
0

The following is a purely aesthetic option using a [t]op-aligned array:

enter image description here

\documentclass{article}

\usepackage{lipsum}
\usepackage{amsmath}

\begin{document}

\lipsum*[1]
\begin{align*}
    \min \quad & x_1 + 3 x_2 - 5 x_3 + 2 x_4 - 7 x_5 \\
    \text{subject to} \quad & 
      \renewcommand{\arraystretch}{1.2}
      \setlength{\arraycolsep}{0pt}
      \begin{array}[t]{ *{7}{r} }
               & {}   3 x_2 &            & {} - 8 x_4 & {} +   x_5 & {}  =  {} &  15 \\
         4 x_1 & {} - 8 x_2 &            & {} + 2 x_4 & {} +   x_5 & {}  =  {} &  25 \\
           x_1 & {} + 8 x_2 &            & {} - 5 x_4 &            & {}\geq {} &  29 \\
        -2 x_1 & {} - 5 x_2 & {} - 5 x_3 &            & {} + 3 x_5 & {}\geq {} & -27 \\
                                      \multicolumn{5}{r}{x_2, x_4} & {}\geq {} &   0 \\
                                           \multicolumn{5}{r}{x_5} & {}\leq {} &   0
      \end{array}
\end{align*}  
\lipsum[2]

\end{document}

You must log in to answer this question.

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