# Usage of ampersand

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}

• See eqnarray vs align before going any further...
– Werner
Jan 15, 2018 at 21:28
• welcome to tex.sx. do follow @Werner's recommendation. Jan 15, 2018 at 21:33
• 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. Jan 15, 2018 at 21:35

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} I’m not sure I’ve understood what you want: see if this can do. 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}
\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: 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}
\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}


The following is a purely aesthetic option using a [t]op-aligned array: \documentclass{article}

\usepackage{lipsum}
\usepackage{amsmath}

\begin{document}

\lipsum*
\begin{align*}
\min \quad & x_1 + 3 x_2 - 5 x_3 + 2 x_4 - 7 x_5 \\
\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

\end{document}