我正在处理需要分成多行的方程式。我编写的代码如下:
\begin{equation}
\begin{aligned}
O_{max} = w_1 \Sigma_{a=1}^{m} \Sigma_{b=a+1}^{n} (-\left|CPT_a
- CPT_b\right|)\\
& + w_2 \Sigma_{j=1}^{m} (DIF_j) + w_3 \Sigma_{j=1}^{m}
(INT_j/\Sigma_{x=1}^{n} x_{ij})
\end{aligned}
\label{equ:ho}
\end{equation}
另一个是
\begin{align}
\begin{split}
nr(G_i,r) =
\begin{cases}
1 & \text{r is naturally played by one member of $G_i$}\\
-2 & \text{r is not naturally played in $G_i$} \\
-p & \text{r is naturally played by p members in $G_i$}\\
\end{cases}
\end{split} \nonumber \\
\begin{split}
nb(G_i) = \Sigma_{r=1}^{9} nr(G_i,r)\\
& max_{\forall G\in C} \left( b(G) =
\frac{\Sigma_{i=1}^{g}nb(G_i)}{g}\right)
\end{split}
\label{equ:yannibelli}
\end{align}
每个方程的对齐方式都不一样(第二部分向右并超出了页面边缘)。请问我该如何修复它们?
答案1
编辑:2020/01/01,针对用户@Mico 的评论. 首次与用户的重要建议对齐@Sigur是:
\documentclass[a4paper,12pt]{article}
\usepackage{amsmath,amssymb}
\begin{document}
\begin{equation}
\begin{aligned}
O_{\max}& = w_1 \sum_{a=1}^{m} \sum_{b=a+1}^{n} (-\lvert\text{CPT}_a
-\text{CPT}_b\rvert)\\
&\quad + w_2 \sum_{j=1}^{m} (\text{DIF}_j) + w_3 \sum_{j=1}^{m}
(\text{INT}_j/\sum_{x=1}^{n} x_{ij})
\end{aligned}
\label{equ:ho}
\end{equation}
\end{document}
对于第二段代码我建议的对齐方式是:
\documentclass[a4paper,12pt]{article}
\usepackage{amsmath,amssymb}
\begin{document}
\[\begin{aligned}
\mathrm{nr}(G_i,r) & =
\begin{cases}
1 & \text{$r$ is naturally played by one member of $G_i$}\\
-2 & \text{$r$ is not naturally played in $G_i$} \\
-p & \text{$r$ is naturally played by $p$ members in $G_i$}\\
\end{cases}\\[3pt]
\mathrm{nb}(G_i) & = \sum_{r=1}^{9} \mathrm{nr}(G_i,r)\\
& = \max_{\forall G\in C} \left( b(G) = \frac{\sum\limits_{r=1}^{9}\mathrm{nb}(G_i)}{g}\right)
\label{equ:yannibel}
\end{aligned}
\]
\end{document}
答案2
对齐要求使用对齐符号 - &
- 正确指示用于对齐目的的连续行内的水平位置。在第一个构造中,您没有使用任何对齐符号。它应该是这样的:
\begin{equation}
\begin{aligned}
O_{\max} &= w_1 \sum_{a = 1}^m \sum_{b = a + 1}^n (-\lvert CPT_a
- CPT_b \rvert) \\
&\phantom{{}={}} + w_2 \sum_{j = 1}^m (DIF_j) + w_3 \sum_{j = 1}^m
(INT_j / \sum_{x = 1}^n x_{ij})
\end{aligned}
\end{equation}
请注意使用\max
and\sum
代替max
and \Sigma
。您也可以考虑将\CPT
and定义\DIF
为数学运算符。
然后,对于第二个构造,这里似乎没有必要split
。您可以使用嵌套equation
-aligned
就像第一个一样:
\begin{equation}
\begin{aligned}
nr(G_i, r) &=
\begin{cases}
1 & \text{$r$ is naturally played by one member of $G_i$}\\
-2 & \text{$r$ is not naturally played in $G_i$} \\
-p & \text{$r$ is naturally played by $p$ members in $G_i$}\\
\end{cases} \\
nb(G_i) &= \sum_{r = 1}^9 nr(G_i, r) \\
& \max_{\forall G \in C} \left( b(G) = \frac{\sum_{i = 1}^g nb(G_i)}{g} \right)
\end{aligned}
\end{equation}
这实际上取决于您希望如何对齐以及编号。我在此的假设是基于每个构造的单一编号。
答案3
我会这样做(使用\sum
而不是\Sigma
):
\documentclass{article}
\usepackage{amsmath,amssymb}
\begin{document}
\begin{equation}
\begin{aligned}
O_{\max} &= w_1 \sum_{a=1}^{m} \sum_{b=a+1}^{n} (-|CPT_a - CPT_b|) \\
&\quad + w_2 \sum_{j=1}^{m} DIF_j + w_3 \sum_{j=1}^{m} \Bigl(INT_j/\sum_{i=1}^{n} x_{ij}\Bigr)
\end{aligned}
\label{equ:ho}
\end{equation}
or another version with \verb|\mathrm{}|:
\begin{equation}
\begin{aligned}
O_{\max} &= w_1 \sum_{a=1}^{m} \sum_{b=a+1}^{n} (-|\mathrm{CPT}_a - \mathrm{CPT}_b|) \\
&\quad + w_2 \sum_{j=1}^{m} \mathrm{DIF}_j + w_3 \sum_{j=1}^{m} \Bigl(\mathrm{INT}_j/\sum_{i=1}^{n} x_{ij}\Bigr)
\end{aligned}
\label{equ:ho}
\end{equation}
\end{document}