我真的搞不懂这个 alignat 环境是如何工作的,我试图对齐至少我写索引的部分。我检查了问题,但似乎什么都不起作用。我想在两个不同的 alignat 环境中沿绿线对齐方程。谢谢。T
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[]{algorithm2e}
\usepackage{amsmath,amsfonts, empheq,mathtools}
\usepackage{caption}
\usepackage{array}
\usepackage{tabularx}
\usepackage{pifont}
\usepackage{float}
\usepackage{tikz}
\def\arraystretch{1.5}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\def\checkmark{\tikz\fill[scale=0.4](0,.35) -- (.25,0) -- (1,.7) -- (.25,.15) -- cycle;}
\begin{document}
\clearpage
\textbf{\textit{Subject to;}}
\begin{alignat}{2}
\nonumber\\
&f^r(x)= P^r_{loss} + Q_{loss}^r & & \forall r \in R\\[1mm]
&h_1^r:=\begin{cases}
|V|_{lower} - |V_i^r|\textrm{, } & |V_i^r| \leq |V|_{lower}\\[-1mm]
|V_i^r|-|V|_{upper}\textrm{, } & |V_i^r|\geq|V|_{upper} \\[-1mm]
\hfill 0 \textrm{, } & |V|_{lower} \geq |V_i^r| \leq |V|_{upper}\\
\end{cases} & & \forall i \in N \textrm{ , } \forall r \in R \\[1mm]
&h_2^r:=\begin{cases}
\omega_{lower} - \omega_r \textrm{, } & \omega_r \leq \omega_{lower}\\[-1mm]
\omega_r-\omega_{upper}\textrm{, } & \omega_r \geq \omega_{upper} \\[-1mm]
\hfill 0 \textrm{, } & \omega_{lower} \geq \omega_r \leq \omega_{upper}\\
\end{cases} & & \forall r \in R \\[2mm]
&h_3^r:=\begin{cases}
I_{lower} - I_{ij}\textrm{, } & I_{ij} \leq I_{lower}\\[-1mm]
I_{ij}-I_{upper}\textrm{, } & I_{ij}\geq I_{upper} \\[-1mm]
\hfill 0 \textrm{, } & I_{lower} \geq I_{ij} \leq I_{upper}\\
\end{cases} & & \forall i,j \in R \\[1mm]
&x= \left\{ m_{p_i} \dots m_{p_{|B|}}, n_{q_i} \dots n_{q_{|B|}} \right\} & & \forall i \in B
\end{alignat}
\begin{alignat}{2}
&\min_{x\in \mathcal{R}^n} \hat{\mathcal{L}}(x) = \sum_{r\in R} \dfrac{\mathcal{L}^r(x)}{|R|} & &\forall r \in R\\
&\mathcal{L}^r(x) := \begin{cases}
\hat{h}^r(x) := h^r_{max}(x) \textrm{, } & h_{max}^r > 0\\
\hat{f}^r(x):= \arctan\left[ f^r(x)\right] - \dfrac{\pi}{2}\textrm{, } & h_{max}^r \leq 0
\end{cases} & & \forall r \in R\\
&h_{max}^r = \max\left(h_1^r,h_2^r,h_3^r\right) && \forall r \in R
\end{alignat}
\end{document}
答案1
如果您想在两部分之间设置文本,请使用单一alignat
环境并使用。\intertext
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{alignat}{2}
\makebox[1em][l]{\bfseries\itshape Subject to} & &\quad& \nonumber\\
&f^r(x)= P^r_{\mathrm{loss}} + Q_{\mathrm{loss}}^r && \forall r \in R\\[1ex]
&h_1^r:=\begin{cases}
|V|_{\mathrm{lower}} - |V_i^r|, & |V_i^r| \leq |V|_{\mathrm{lower}}\\
|V_i^r|-|V|_{\mathrm{upper}}, & |V_i^r|\geq|V|_{\mathrm{upper}} \\
0, & |V|_{\mathrm{lower}} \geq |V_i^r| \leq |V|_{\mathrm{upper}}
\end{cases} & & \forall i \in N,\ \forall r \in R \\[1ex]
&h_2^r:=\begin{cases}
\omega_{\mathrm{lower}} - \omega_r , & \omega_r \leq \omega_{\mathrm{lower}}\\
\omega_r-\omega_{\mathrm{upper}}\textrm{, } & \omega_r \geq \omega_{\mathrm{upper}} \\
0 , & \omega_{\mathrm{lower}} \geq \omega_r \leq \omega_{\mathrm{upper}}
\end{cases} & & \forall r \in R \\[1ex]
&h_3^r:=\begin{cases}
I_{\mathrm{lower}} - I_{ij}, & I_{ij} \leq I_{\mathrm{lower}}\\
I_{ij}-I_{\mathrm{upper}}, & I_{ij}\geq I_{\mathrm{upper}} \\
0, & I_{\mathrm{lower}} \geq I_{ij} \leq I_{\mathrm{upper}}
\end{cases} & & \forall i,j \in R \\[1ex]
&x= \{ m_{p_i} \dots m_{p_{|B|}}, n_{q_i} \dots n_{q_{|B|}} \} & & \forall i \in B \\
\intertext{Here we can add text to comment and divide the two parts;
this text can also wrap across lines}
&\!\min_{x\in \mathcal{R}^n}\hat{\mathcal{L}}(x) =
\sum_{r\in R} \dfrac{\mathcal{L}^r(x)}{|R|} & &\forall r \in R \\[1ex]
&\mathcal{L}^r(x) := \begin{cases}
\hat{h}^r(x) := h^r_{\mathrm{max}}(x), & h_{\mathrm{max}}^r > 0 \\[1ex]
\hat{f}^r(x):= \arctan[f^r(x)] - \frac{\pi}{2}, & h_{\mathrm{max}}^r \leq 0
\end{cases} & & \forall r \in R \\[1ex]
&h_{\mathrm{max}}^r = \max(h_1^r,h_2^r,h_3^r) && \forall r \in R
\end{alignat}
\end{document}
我做了一些小改动;请检查一下,因为它们符合常见做法。