對齊環境中的編號無法正常運作

對齊環境中的編號無法正常運作

我使用 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}

附錄:這些方程式寫起來很乏味——而且作為讀者也不容易理解——很大一部分原因是在總和下標位置存在 4 元組。如果可以為這些元組建立縮寫(例如,\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}

相關內容