对齐环境中的编号无法正常工作

对齐环境中的编号无法正常工作

我使用 Align 环境编写 ILP 模型,编号出错:不是让每个数字都遵循其约束,而是让所有约束都遵循,最后才是所有数字。如果我在另一个文档中使用相同的代码,它可以正常工作。可能是什么问题?

\begin{align}
\mbox{min.} \quad & \sum_{p \in P} \sum_{(t_{1},v_{1},t_{2},v_{2}) \in WT} c_{v_{1},v_{2}}x^p_{t_{1},v_{1},t_{2},v_{2}}  \notag \\
\mbox{s.t.} \quad 
        & \sum_{(t_{2},v_{2},t_{1},v_{1}) \in BS(t_{1},v_{1})} x^p_{t_{2},v_{2},t_{1},v_{1}}  - \sum_{(t_{1},v_{1},t_{2},v_{2}) \in FS(t_{1},v_{1})} x^p_{t_{1},v_{1},t_{2},v_{2}}\; = \; 0\qquad \forall p \in P,(v_{1},t_{1}) \in VT \\
        &  - \sum_{(p,o,t_{2},v_{2}) \in FS(p,o)} x^p_{p,o,t_{2},v_{2}}\; = \; - d_p \qquad  \forall p \in  P\\
        & \sum_{(t_{1},v_{1},p,w) \in BS(p,w)} x^p_{t_{1},v_{1},p,w}  \; = \; + d_p \qquad  \forall p \in  P\\
        & \sum_{p \in P} \sum_{(t_{2},v_{2},t_{1},v_{1}) \in BS(t_{1},v_{1})} x^p_{t_{2},v_{2},t_{1},v_{1}}  \; \leq \; Q \qquad\qquad\qquad\qquad\qquad\qquad\qquad\forall (v_{1},t_{1}) \in VT \\     
        & x^p_{t_{1},v_{1},t_{2},v_{2}} \in Z \qquad \qquad \qquad  \qquad \qquad \quad \forall p \in P, \forall (t_{1},v_{1},t_{2},v_{2}) \in WT     
 \end{align}\\
 \\

答案1

我建议你将一个alignat{2}环境嵌入另一个环境中gather*。这两个环境均由包提供amsmath,并由包自动加载mathtools。我还会使用\smashoperator宏(由mathtools包提供)来更紧凑地排版某些指令下方的材料\sum

在此处输入图片描述

\documentclass{article} % or some other suitable document class   
\usepackage[letterpaper,margin=1in]{geometry} % set page parameters as needed   
\usepackage{mathtools} % for '\smashoperator' macro
\newcommand\vn[1]{\mathit{#1}}

\begin{document}
\begin{gather*}
  \min \sum_{p \in P\mathstrut} \  
  \smashoperator[r]{\sum_{(t_{1},v_{1},t_{2},v_{2}) \in \vn{\vn{WT}}} }
  c_{v_{1},v_{2}}x^p_{t_{1},v_{1},t_{2},v_{2}} \\
\shortintertext{such that}
\begin{alignat}{2} 
  \smashoperator{\sum_{(t_{2},v_{2},t_{1},v_{1}) \in \vn{BS}(t_{1},v_{1})}} 
  x^p_{t_{2},v_{2},t_{1},v_{1}}  
  \quad-\quad 
  \smashoperator{\sum_{(t_{1},v_{1},t_{2},v_{2}) \in \vn{FS}(t_{1},v_{1})}} 
  x^p_{t_{1},v_{1},t_{2},v_{2}}
  &= 0
  &\qquad&\forall p \in P,\ \forall(v_{1},t_{1}) \in \vn{VT} \\
  -\smashoperator{\sum_{(p,o,t_{2},v_{2}) \in \vn{FS}(p,o)}} 
  x^p_{p,o,t_{2},v_{2}} 
  &= -d_p 
  &&\forall p \in P \\
  \smashoperator{\sum_{(t_{1},v_{1},p,w) \in \vn{BS}(p,w)}} 
  x^p_{t_{1},v_{1},p,w} 
  &= + d_p 
  &&\forall p \in  P\\
  \sum_{p \in P\mathstrut} \ 
  \smashoperator[r]{\sum_{(t_{2},v_{2},t_{1},v_{1}) \in \vn{BS}(t_{1},v_{1})}} 
  x^p_{t_{2},v_{2},t_{1},v_{1}}  
  &\leq Q 
  &&\forall (v_{1},t_{1}) \in \vn{VT} \\     
  x^p_{t_{1},v_{1},t_{2},v_{2}} &\in Z 
  && \forall p \in P,\ 
  \forall (t_{1},v_{1},t_{2},v_{2}) \in \vn{WT}     
\end{alignat}
\end{gather*}
\end{document}

附录:这些方程式之所以写起来很乏味,而且读者也很难理解,很大一部分原因是四元组出现在和下标位置。如果可以为这些元组创建缩写(例如,\tau_1thru \tau_4)并使用双和符号,则可以将方程式重写如下:

在此处输入图片描述

\documentclass{article}       
\usepackage{mathtools} % for '\smashoperator' macro
\newcommand\vn[1]{\mathit{#1}}
\newcommand\doublesum{\mathop{\sum\sum}}

\begin{document}

\begin{gather*}
  \min \smashoperator{\doublesum_{p \in P,\;\tau_1\in\vn{WT}}}
  c^{}_{v_{1},v_{2}}x^p_{\tau_1} \\
\intertext{such that}
\begin{alignat}{2} 
  \smashoperator{\sum_{\tau_1\in\vn{FS}(\tau)}} 
  x^p_{\tau_1}
  &= 
  \smashoperator[r]{\sum_{\tau_2\in\vn{BS}(\tau)}} 
  x^p_{\tau_2}
  &\quad&
  \forall p \in P,\ \forall\tau\in\vn{VT} \\
  -\smashoperator{\sum_{\tau_3\in\vn{FS}(p,o)}} 
  x^p_{\tau_3} 
  &= -d_p 
  &&\forall p \in P \\
  \smashoperator{\sum_{\tau_4\in\vn{BS}(p,w)}} 
  x^p_{\tau_4} 
  &= +d_p 
  &&\forall p \in P \\
  \smashoperator{\doublesum_{p \in P,\;\tau_2\in\vn{BS}(\tau)}} 
  x^p_{\tau_2}  
  &\leq Q 
  &&\forall \tau\in\vn{VT} \\     
  x^p_{\tau_1} &\in Z 
  && \forall p \in P,\ \forall \tau_1\in\vn{WT}     
\end{alignat}
\end{gather*}
where   $\tau\equiv(t_{1},v_{1})$, 
      $\tau_1\equiv(t_{1},v_{1},t_{2},v_{2})$, 
      $\tau_2\equiv(t_{2},v_{2},t_{1},v_{1})$, 
      $\tau_3\equiv(p,o,t_{2},v_{2})$, and
      $\tau_4\equiv(t_{1},v_{1},p,w)$.
\end{document}

相关内容