“&” 符号的用法

“&” 符号的用法

我正在尝试将线性程序转换为标准形式,但我无法使用 & 将等号和不等号放在同一列中。如果我尝试添加更多 &,则会出现以下错误。

\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}

答案1

我想你想要第一个解决方案,但我认为第二个解决方案看起来更好:

\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} 

在此处输入图片描述

答案2

我不确定我是否明白你想要什么:看看这是否可以做到。

以下代码的输出

该输出由以下代码生成:

% 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}

还有一种可能性:

第二个代码示例的输出

代码:

% 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}

答案3

以下是使用[t]op-aligned 的纯粹美学选项array

在此处输入图片描述

\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}

相关内容