使對齊的方程式變化對齊以避免新行上的方程式編號

使對齊的方程式變化對齊以避免新行上的方程式編號

我需要編寫一個由多個限制條件組成的數學規劃模型。約束表示為兩列行:第一列是方程,第二列是其域,例如

x_i > l_i & \forall i \in S

但是兩列都可能很長,因此如果一方面最好以某種方式將所有列水平對齊,但另一方面,列可能最終會被垂直分割或列印超出頁面的其他元素。

我當時認為一個不錯的解決方案是使用一個類似對齊的環境,以便每個第一列與其他列對齊,每個第二列也與其他列對齊。但是,如果方程式沒有空間。 number 留在該行然後我希望第二列(即域)右對齊,以便填充第一列之後的空間以避免 eq.要在新行上列印的數字。

考慮以下

\documentclass[a4,13pt,reqno,twoside, openright]{article}
\usepackage[utf8x]{inputenc}
\usepackage{float}
\usepackage{subfig}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}

\allowdisplaybreaks

\textwidth = 14cm
 \hoffset = -1.5cm
 \voffset = -2.0cm

\begin{document}
\begin{subequations}
\begin{align}
& y^D_{tzgm} \le y_{tzgm} & \forall t \in T, z \in Z, g \in G_z, m \in \overline{M}_{zg}
\\
  & x_{tzg} \leq \sum_{m \in M_{zg}} P_{zgm} \cdot y_{tzgm} + \sum_{m \in \bar M_{zg}} (P^D_{zgm} - P_{zgm}) \cdot y^D_{tzgm} & \forall t \in T, z \in Z, g \in G_z\\
  &x_{tzg} \geq \sum_{m \in M_{zg}} p_{zgm} \cdot y_{tzgm} + \sum_{m \in \bar M_{zg}} (p^D_{zgm} - p_{zgm}) \cdot y^D_{tzgm} & \forall t \in T, z \in Z, g \in G_z\\
  & o_{1zh} = v_{0h}  &\forall z \in Z, h \in H_z\\
  & o_{(|T|+1)zh} = v_{(|T|+1)h} & \forall z \in Z, h \in H_z\\
  & o_{tzh} + n_{th} + \eta_{h} \cdot m_{tzh} = o_{(t+1)zh} + s_{tzh} + l_{tzh} & \forall t \in T, z \in Z, h \in H_z
\end{align}
\end{subequations}

\end{document}

在此輸入影像描述

正如你所看到的,我得到了每一個方程式。新行上的數字,因為第一個不等式的定義域太長。透過手動添加空間獲得的我想要的結果的近似值是

    \documentclass[a4,13pt,reqno,twoside, openright]{article}
\usepackage[utf8x]{inputenc}
\usepackage{float}
\usepackage{subfig}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}

\allowdisplaybreaks

\textwidth = 14cm
 \hoffset = -1.5cm
 \voffset = -2.0cm

\begin{document}
\begin{subequations}
\begin{align}
& y^D_{tzgm} \le y_{tzgm} \qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad \mathrlap{\forall t \in T, z \in Z, g \in G_z, m \in \overline{M}_{zg}}
\\
  & x_{tzg} \leq \sum_{m \in M_{zg}} P_{zgm} \cdot y_{tzgm} + \sum_{m \in \bar M_{zg}} (P^D_{zgm} - P_{zgm}) \cdot y^D_{tzgm} & \forall t \in T, z \in Z, g \in G_z\\
  &x_{tzg} \geq \sum_{m \in M_{zg}} p_{zgm} \cdot y_{tzgm} + \sum_{m \in \bar M_{zg}} (p^D_{zgm} - p_{zgm}) \cdot y^D_{tzgm} & \forall t \in T, z \in Z, g \in G_z\\
  & o_{1zh} = v_{0h}  &\forall z \in Z, h \in H_z\\
  & o_{(|T|+1)zh} = v_{(|T|+1)h} & \forall z \in Z, h \in H_z\\
  & o_{tzh} + n_{th} + \eta_{h} \cdot m_{tzh} = o_{(t+1)zh} + s_{tzh} + l_{tzh} & \forall t \in T, z \in Z, h \in H_z
\end{align}
\end{subequations}

\end{document}

在此輸入影像描述

其次,您認為有更好的方法來排版這些模型嗎?

TIA

答案1

我剛剛將第一行標籤放置在零寬度、右對齊的方塊中。

\documentclass[a4,13pt,reqno,twoside, openright]{article}
\usepackage[utf8x]{inputenc}
\usepackage{float}
\usepackage{subfig}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}

\allowdisplaybreaks

\textwidth = 14cm
 \hoffset = -1.5cm
 \voffset = -2.0cm

\begin{document}
\begin{subequations}
\begin{align}
& y^D_{tzgm} \le y_{tzgm} & \makebox[0pt][r]{$\forall t \in T, z \in Z, g \in G_z, m \in \overline{M}_{zg}$}
\\
  & x_{tzg} \leq \sum_{m \in M_{zg}} P_{zgm} \cdot y_{tzgm} + \sum_{m \in \bar M_{zg}} (P^D_{zgm} - P_{zgm}) \cdot y^D_{tzgm} & \forall t \in T, z \in Z, g \in G_z\\
  &x_{tzg} \geq \sum_{m \in M_{zg}} p_{zgm} \cdot y_{tzgm} + \sum_{m \in \bar M_{zg}} (p^D_{zgm} - p_{zgm}) \cdot y^D_{tzgm} & \forall t \in T, z \in Z, g \in G_z\\
  & o_{1zh} = v_{0h}  &\forall z \in Z, h \in H_z\\
  & o_{(|T|+1)zh} = v_{(|T|+1)h} & \forall z \in Z, h \in H_z\\
  & o_{tzh} + n_{th} + \eta_{h} \cdot m_{tzh} = o_{(t+1)zh} + s_{tzh} + l_{tzh} & \forall t \in T, z \in Z, h \in H_z
\end{align}
\end{subequations}

\end{document}

在此輸入影像描述

答案2

因為你並不真正想要對齊,所以你可以使用gather填充膠並強制將條件分開,除非另有說明這裡你通常不能\hfill在 ams 對齊中使用,所以需要先稍微調整一下。

為了保留程式碼,重新定義,gather當然可以基於此創建一個新環境,保持原始環境gather不變。

在此輸入影像描述

\documentclass[a4,13pt,reqno,twoside, openright]{article}
\usepackage[utf8x]{inputenc}
\usepackage{float}
\usepackage{subfig}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}

\allowdisplaybreaks

\textwidth = 14cm
 \hoffset = -1.5cm
 \voffset = -2.0cm

\makeatletter
\def\set@gather@field{%
    \iftagsleft@
        \global\lineht@\ht\z@
    \else
        \global\lineht@\dp\z@
    \fi
    \kern\eqnshift@
    \unhbox\z@
    \hfil
}

\def\gather@#1{%
    \ingather@true \let\split\insplit@
    \let\tag\tag@in@align \let\label\label@in@display
    \chardef\dspbrk@context\z@
    \intertext@ \displ@y@ \Let@
    \let\math@cr@@@\math@cr@@@gather
    \gmeasure@{#1}%
    \global\shifttag@false
    \tabskip\z@skip
    \global\row@\@ne
    \halign to\displaywidth\bgroup
        \strut@
        \setboxz@h{$\m@th\displaystyle##$}%
        \calc@shift@gather
        \set@gather@field
        \tabskip\@centering
       &\setboxz@h{\strut@{##}}%
        \place@tag@gather
        \tabskip \iftagsleft@ \gdisplaywidth@ \else \z@skip \span\fi
        \crcr
        #1%
}

\makeatother


\begin{document}
\begin{subequations}
\begin{gather}
 y^D_{tzgm} \le y_{tzgm} \quad\hfill \forall t \in T, z \in Z, g \in G_z, m \in \overline{M}_{zg}
\\
   x_{tzg} \leq \sum_{m \in M_{zg}} P_{zgm} \cdot y_{tzgm} + \sum_{m \in \bar M_{zg}} (P^D_{zgm} - P_{zgm}) \cdot y^D_{tzgm} \quad\hfill\forall t \in T, z \in Z, g \in G_z\\
  x_{tzg} \geq \sum_{m \in M_{zg}} p_{zgm} \cdot y_{tzgm} + \sum_{m \in \bar M_{zg}} (p^D_{zgm} - p_{zgm}) \cdot y^D_{tzgm} \quad\hfill\forall t \in T, z \in Z, g \in G_z\\
   o_{1zh} = v_{0h} \quad\hfill\forall z \in Z, h \in H_z\\
   o_{(|T|+1)zh} = v_{(|T|+1)h} \quad\hfill\forall z \in Z, h \in H_z\\
   o_{tzh} + n_{th} + \eta_{h} \cdot m_{tzh} = o_{(t+1)zh} + s_{tzh} + l_{tzh} \quad\hfill\forall t \in T, z \in Z, h \in H_z
\end{gather}
\end{subequations}

\end{document}

答案3

您可以為此目的定義一個特定命令:

\documentclass[a4paper]{article}
\usepackage[textwidth=14cm,showframe]{geometry}
\usepackage{amsmath}

\newcommand{\eqcond}[3][3em]{%
  \makebox[\dimexpr\displaywidth-#1][s]{%
    $\displaystyle#2\hfill#3$}%
}

\allowdisplaybreaks

\begin{document}
\begin{subequations}
\begin{align}
&\eqcond
   {y^D_{tzgm} \le y_{tzgm}}
   {\forall t \in T, z \in Z, g \in G_z, m \in \overline{M}_{zg}}
\\
&\eqcond
   {x_{tzg} \leq \sum_{m \in M_{zg}} P_{zgm} \cdot y_{tzgm} + 
    \sum_{m \in \bar M_{zg}} (P^D_{zgm} - P_{zgm}) \cdot y^D_{tzgm}}
   {\forall t \in T, z \in Z, g \in G_z}
\\
&\eqcond
   {x_{tzg} \geq \sum_{m \in M_{zg}} p_{zgm} \cdot y_{tzgm} + 
    \sum_{m \in \bar M_{zg}} (p^D_{zgm} - p_{zgm}) \cdot y^D_{tzgm}}
   {\forall t \in T, z \in Z, g \in G_z}
\\
&\eqcond
   {o_{1zh} = v_{0h}}
   {\forall z \in Z, h \in H_z}
\\
&\eqcond
   {o_{(|T|+1)zh} = v_{(|T|+1)h}}
   {\forall z \in Z, h \in H_z}
\\
&\eqcond
   {o_{tzh} + n_{th} + \eta_{h} \cdot m_{tzh} = 
    o_{(t+1)zh} + s_{tzh} + l_{tzh}}
   {\forall t \in T, z \in Z, h \in H_z}
\end{align}
\end{subequations}

\end{document}

有一個可選參數\eqcond;隨著\eqcond[6em]{...}{...}你的減少盒子的寬度。這樣\eqcond[0em]你就會得到全寬度(並且方程式編號將被推到線下方。

我用了,這比篡改andgeometry更好;此選項僅用於顯示邊距。\hoffset\voffsetshowframe

也可以為超滿線路新增一張支票。

在此輸入影像描述

答案4

另一個解決方案是僅在必要時將量詞放在下面的一行(未編號)上。flalign根據量詞的對齊方式,可以透過兩種方式對環境完成此操作。由於下標過大,我趁機抑制了 sigma 之後的多餘空間。

        \documentclass[a4,11pt,reqno,twoside, openright]{article}
        \usepackage[utf8x]{inputenc}
        \usepackage{graphicx}
        \usepackage{mathtools}
        \usepackage{amsfonts}
        \usepackage{amssymb}
        \usepackage[textwidth = 14cm, nomarginpar, showframe]{geometry}%
        \allowdisplaybreaks

        \begin{document}

        \begin{subequations}
        \begin{flalign}
        \hspace{4em}  &  & y^D_{tzgm} & ≤ y_{tzgm}  &\forall t \in T, z &\in Z, g \in G_z, m \in \overline{M}_{zg} \\%
          & & x_{tzg} &\leq \mathrlap{\sum_{\mathclap{m \in M_{zg}}} P_{zgm} · y_{tzgm} + \sum_{\mathclap{m \in \bar M_{zg}}} (P^D_{zgm} - P_{zgm}) · y^D_{tzgm}}\\[-12pt]
        \notag &  &  &  &   & \forall t \in T, z \in Z, g \in G_z \\
         & & x_{tzg} & \geq \mathrlap{\sum_{\mathclap{m \in M_{zg}}} p_{zgm} · y_{tzgm} + \sum_{\mathclap{m \in \bar M_{zg}}} (p^D_{zgm} - p_{zgm}) · y^D_{tzgm}}\\[-12pt]
         \notag &  &  &  &  &\forall t \in T, z \in Z,  g \in G_z \\
         &   & o_{1zh}  & = v_{0h}  & & \forall z \in Z, h \in H_z \\
         &   & o_{(|T|+1)zh} &  = v_{(|T|+1)h} & & \forall z \in Z, h\in H_z \\
        &   & \mathllap{o_{tzh} + n_{th} + η_{h} · m_{tzh}}  & =\mathrlap{ o_{(t+1)zh} + s_{tzh} + l_{tzh} } &  & \forall t \in T, z \in Z, h \in H_z
        \end{flalign}
        \end{subequations}

        \begin{subequations}
        \begin{flalign}
          &  & y^D_{tzgm}   &  ≤ y_{tzgm}  & \hspace{8em}&\  \mathllap{\forall t \in T, z \in Z, g \in G_z, m \in \overline{M}_{zg}} \\%
          & & x_{tzg} &\leq \mathrlap{\sum_{\mathclap{m \in M_{zg}}} P_{zgm}   · y_{tzgm} + \sum_{\mathclap{m \in \bar M_{zg}}} (P^D_{zgm} - P_{zgm})   · y^D_{tzgm}}\\[-12pt]
        \notag &  &  &  &   & \mathllap{\forall t \in T, z \in Z, g \in G_z} \\
         & & x_{tzg}  & \geq \mathrlap{\sum_{\mathclap{m \in M_{zg}}} p_{zgm} · y_{tzgm} + \sum_{\mathclap{m \in \bar M_{zg}}} (p^D_{zgm} - p_{zgm}) · y^D_{tzgm}}\\[-12pt]
         \notag &  &  &  &  & \mathllap{\forall t \in T, z \in Z, g \in G_z} \\
         &   & o_{1zh}  & = v_{0h}  & & \mathllap{∀z \in Z, h \in H_z} \\
         &   & o_{(|T|+1)zh} &  = v_{(|T|+1)h} & &  \mathllap{\forall z \in Z, h \in H_z} \\
        &   & \mathllap{o_{tzh} + n_{th} + η_{h} · m_{tzh}} & =\mathrlap{ o_{(t+1)zh} + s_{tzh} + l_{tzh} } & & \mathllap{\forall t \in T, z \in Z, h \in H_z}
        \end{flalign}
        \end{subequations}
        \end{document} 

在此輸入影像描述

相關內容