How to edit the linear programming in LaTeX?

A regular array would suffice here, since the alignment is pretty rigid horizontally:

enter image description here

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}
\[
  \begin{array}{r@{}r@{}r@{}l}
    \text{Max} \quad z=x_1 &{} + 12x_2 \\[\jot]
    \text{s.t.}\qquad 3x_1 &{} + \phantom{12}x_2 &{} + 12x_3 &{} \leq 5 \\
                      x_1 &         &{} +   \phantom{12}x_3 &{} \leq 16 \\
                    15x_1 &{} + \phantom{12}x_2 &           &{} = 14 \\
     \multicolumn{4}{c}{x_j \geq 0, \quad j=1,2,3.}
  \end{array}
\]
\end{document}

The use of \phantom is to allow for proper spacing and alignment.


Here might be another alignment option, mainly for the first column:

enter image description here

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}
\[
  \begin{array}{ll@{}r@{}r@{}l}
    \text{Max} & z=x_1 &{} + 12x_2 \\[\jot]
    \text{s.t.}& \phantom{15}\llap{3}x_1 &{} + \phantom{12}x_2 &{} + 12x_3 &{} \leq 5 \\
    &    \phantom{15}x_1 &     &{} +   \phantom{12}x_3 &{} \leq 16 \\
    &              15x_1 &{} + \phantom{12}x_2 &           &{} = 14 \\
    & \multicolumn{4}{l}{x_j \geq 0, \quad j=1,2,3.}
  \end{array}
\]
\end{document}

Basically you have a text column, then repeated (math) columns where first one is right-aligned, then a relation column, then left aligned, and again relation column. Except the last line isn't aligned at all, and the width of the first line shouldn't be taken into account with the alignment of subsequent lines.

One way to do this is:

{\let\DS\displaystyle\mathsurround=0pt\openup\jot
\halign{\hfil#\hfil\enspace&& $\hfil\DS#$& ${}#{}$& $\DS{}#\hfil$& ${}#{}$\crcr
  Max & z = x_1 & + & 12x_2 \hidewidth\cr
  s.t.& 3x_1    & + & x_2 & + & 12x_3 & \leq & 5 \cr
      & x_1     &   &     & + & x_3   & \leq & 16 \cr
      & 15x_1   & + & x_2 &   &       & =    & 14 \cr
  \noalign{\smallskip $\DS x_j \geq 0, \quad j=1,2,3$.}
}}
\bye

enter image description here

But please note that this is plain TeX way; it should work with LaTeX as well (sans the \bye at the end), but is generally shunned upon.


mathtools provides \mathrlap.
amsmath provides the alignat* environment.

I assume Max and s.t. are not variables, therefore I've typeset them in upright shape.
Lonely and empty {} are providing the right amount of spacing.
The macro \plus is just a shortcut for +{}.

Code

\documentclass{article}
\usepackage{amsmath,mathtools}
\newcommand*\plus{+{}}
\newcommand*\boxSizeOfMax[1]{\makebox[\widthof{Max}][c]{#1}}
\begin{document}

\begin{alignat*}{5}
           \text{Max} \quad & \mathrlap{z = x_1 + 12 x_2}   & & & & & & & & \\
  \boxSizeOfMax{s.t.} \quad & & 13 x_1 & \plus & x_2 & \plus & 12x_3 & \leq{}  &  5 & \\
                            & &    x_1 &       &     & \plus &   x_3 & \leq    & 16 & \\
                            & & 15 x_1 & \plus & x_2 &       &       & =       & 14 & \\
                            & \mathrlap{x_J\geq 0, j = 1, 2, 3.} & & & & & & & & 
\end{alignat*}
\end{document}

Output

Output