下面的代码
\documentclass{report}
\begin{document}
\begin{equation}
\setlength\arraycolsep{1.5pt}
\begin{array}{l@{\qquad} r c r c r}
(P) & z(P) = \min & cx \\
& \mathrm{s.t.} & Ax & = & b \\
& & x & \in & X \\
\end{array}
\end{equation}
\end{document}
产生与整个模型相关的单个方程编号,如下图所示。
我如何为每个约束定义一个数字(无需自己编写)?请参阅下面的示例。
答案1
此答案使用optidef
包。我似乎需要以不同于作为示例发布的内容的方式编写目标函数。否则,函数和约束将单独编号。
以下示例说明了四种不同的用法,提供了不同的对齐方式以及长短表示法。
结果如下:
这是代码:
\documentclass[a4paper,12pt]{report}
\usepackage[nocomma]{optidef}
\begin{document}
Short notation, alternative 1 layout for constraints
\begin{mini!}|s|[1] % mini! = minimize
{x} % optimization variable
{z(P) = \min cx \label{eq:eq1}} % objective function and label
{\label{eq:Example1}} % label for optimizatio problem
{} % optimization result
\addConstraint{Ax}{=b \label{eq:con1}} % constraint 1
\addConstraint{x}{\in X \label{eq:con2}} % constraint 2
\end{mini!}
Short notation, alternative 2 layout for constraints
\begin{mini!}|s|[2] % mini! = minimize
{x} % optimization variable
{z(P) = \min cx \label{eq:eq1}} % objective function and label
{\label{eq:Example1}} % label for optimizatio problem
{} % optimization result
\addConstraint{Ax}{=b \label{eq:con1}} % constraint 1
\addConstraint{x}{\in X \label{eq:con2}} % constraint 2
\end{mini!}
Short notation, alternative 3 layout for constraints
\begin{mini!}|s|[3] % mini! = minimize
{x} % optimization variable
{z(P) = \min cx \label{eq:eq1}} % objective function and label
{\label{eq:Example1}} % label for optimizatio problem
{} % optimization result
\addConstraint{Ax}{=b \label{eq:con1}} % constraint 1
\addConstraint{x}{\in X \label{eq:con2}} % constraint 2
\end{mini!}
Long notation, alternative 2 layout for constraints
\begin{mini!}|l|[2] % mini! = minimize
{x} % optimization variable
{z(P) = \min cx \label{eq:eq1}} % objective function and label
{\label{eq:Example1}} % label for optimizatio problem
{} % optimization result
\addConstraint{Ax}{=b \label{eq:con1}} % constraint 1
\addConstraint{x}{\in X \label{eq:con2}} % constraint 2
\end{mini!}
\end{document}