我的代码如下:
\documentclass[fleqn, 12pt]{article}
\usepackage{amsmath,amsfonts,amssymb}
\usepackage{graphicx}
\graphicspath{ {./images/} }
\setlength{\parskip}{\baselineskip}%
\setlength{\parindent}{0pt}%
\begin{document}
\raggedright
\begin{align}
&\sum\limits_{i = 1}^n X_i[Y_i - (\bar{Y} - \hat{\beta_1}\bar{X}) - \hat{\beta_1} X_i] = 0 \nonumber \\
&\rightarrow \sum\limits_{i = 1}^n X_iY_i - \sum\limits_{i = 1}^n X_i\bar{Y} + \sum\limits_{i = 1}^n X_i\hat{\beta_1}\bar{X} - \sum\limits_{i = 1}^n \hat{\beta_1} X_i^2 = 0 \nonumber \\
&\rightarrow \sum\limits_{i = 1}^n X_i(Y_i - \bar{Y}) + \sum\limits_{i = 1}^n X_i(\hat{\beta_1}\bar{X} - \hat{\beta_1} X_i) = 0 \nonumber \\
&\rightarrow \sum\limits_{i = 1}^n X_i(Y_i - \bar{Y}) = -\sum\limits_{i = 1}^n X_i(\hat{\beta_1}\bar{X} - \hat{\beta_1} X_i) \nonumber \\
&= \sum\limits_{i = 1}^n X_i(\hat{\beta_1} X_i - \hat{\beta_1}\bar{X}) \nonumber \\
&= \hat{\beta_1}\sum\limits_{i = 1}^n X_i( X_i - \bar{X}) \nonumber \\
&\rightarrow \hat{\beta_1} = \dfrac{\sum\limits_{i = 1}^n X_i(Y_i - \bar{Y})}{\sum\limits_{i = 1}^n X_i( X_i - \bar{X})} \nonumber
\end{align}
\end{document}
请注意,在某些时候,我的行会从以 \rightarrow 开头切换到仅以 = 开头,因为我不想多余地重复 \rightarrow。但是,对于最后一行,再次需要 \rightarrow。我希望让 \rightarrow 彼此对齐,并且两行中的 =
&= \sum\limits_{i = 1}^n X_i(\hat{\beta_1} X_i - \hat{\beta_1}\bar{X}) \nonumber \\
&= \hat{\beta_1}\sum\limits_{i = 1}^n X_i( X_i - \bar{X}) \nonumber \\
与前一行中的 = 对齐
&\rightarrow \sum\limits_{i = 1}^n X_i(Y_i - \bar{Y}) (ALIGNED HERE)= -\sum\limits_{i = 1}^n X_i(\hat{\beta_1}\bar{X} - \hat{\beta_1} X_i) \nonumber \\
但我想要最后一句
&\rightarrow \hat{\beta_1} = \dfrac{\sum\limits_{i = 1}^n X_i(Y_i - \bar{Y})}{\sum\limits_{i = 1}^n X_i( X_i - \bar{X})} \nonumber
\end{align}
与以 \rightarrow 开头的所有其他行对齐
&\rightarrow \sum\limits_{i = 1}^n X_iY_i - \sum\limits_{i = 1}^n X_i\bar{Y} + \sum\limits_{i = 1}^n X_i\hat{\beta_1}\bar{X} - \sum\limits_{i = 1}^n \hat{\beta_1} X_i^2 = 0 \nonumber \\
&\rightarrow \sum\limits_{i = 1}^n X_i(Y_i - \bar{Y}) + \sum\limits_{i = 1}^n X_i(\hat{\beta_1}\bar{X} - \hat{\beta_1} X_i) = 0 \nonumber \\
&\rightarrow \sum\limits_{i = 1}^n X_i(Y_i - \bar{Y}) = -\sum\limits_{i = 1}^n X_i(\hat{\beta_1}\bar{X} - \hat{\beta_1} X_i) \nonumber \\
因此我们本质上是维持两种不同的结盟。
我不确定是否有能力为此&
目的保留额外的对齐符号?这似乎是一个简单的解决方案。
如果大家能花时间澄清这一点我将非常感激。
答案1
您可以使用aligned
环境进行=
对齐。我建议使用第二种变体,在我看来,它看起来更好。
\nonumber
顺便说一句,无需在环境的每一行上重复:只需使用align*
环境即可。此外,\limits
显示样式中不需要写入 \sum:这是默认设置。它只\sums
在分数的最后需要(尽管我认为默认设置看起来更好\nolimits
)。另外,您不必加载,amsfonts
因为加载amssymb
会为您完成。
\documentclass[fleqn, 12pt]{article}
\usepackage{mathtools, amssymb}
\usepackage{graphicx}
\graphicspath{ {./images/} }
\setlength{\parskip}{\baselineskip}%
\setlength{\parindent}{0pt}%
\begin{document}
\begin{align*}
&\sum_{i = 1}^n X_i[Y_i - (\bar{Y} - \hat{\beta_1}\bar{X}) - \hat{\beta_1} X_i] = 0 \\
&\rightarrow \sum_{i = 1}^n X_iY_i - \sum_{i = 1}^n X_i\bar{Y} + \sum_{i = 1}^n X_i\hat{\beta_1}\bar{X} - \sum_{i = 1}^n \hat{\beta_1} X_i^2 = 0 \\
&\rightarrow \sum_{i = 1}^n X_i(Y_i - \bar{Y}) + \sum_{i = 1}^n X_i(\hat{\beta_1}\bar{X} - \hat{\beta_1} X_i) = 0 \\
&\rightarrow \sum_{i = 1}^n X_i(Y_i - \bar{Y})
\begin{aligned}[t] & = -\sum_{i = 1}^n X_i(\hat{\beta_1}\bar{X} - \hat{\beta_1} X_i) \\
&= \sum_{i = 1}^n X_i(\hat{\beta_1} X_i - \hat{\beta_1}\bar{X}) \\
&= \hat{\beta_1}\sum_{i = 1}^n X_i( X_i - \bar{X})
\end{aligned} \\
&\rightarrow \hat{\beta_1} = \dfrac{\sum\limits_{i = 1}^n X_i(Y_i - \bar{Y})}{\sum\limits_{i = 1}^n X_i( X_i - \bar{X})}
\end{align*}
\raggedright
\begin{align*}
&\sum_{i = 1}^n X_i[Y_i - (\bar{Y} - \hat{\beta_1}\bar{X}) - \hat{\beta_1} X_i] = 0 \\
&\rightarrow \sum_{i = 1}^n X_iY_i - \sum_{i = 1}^n X_i\bar{Y} + \sum_{i = 1}^n X_i\hat{\beta_1}\bar{X} - \sum_{i = 1}^n \hat{\beta_1} X_i^2 = 0 \\
&\rightarrow \sum_{i = 1}^n X_i(Y_i - \bar{Y}) + \sum_{i = 1}^n X_i(\hat{\beta_1}\bar{X} - \hat{\beta_1} X_i) = 0 \\
&\rightarrow \sum_{i = 1}^n X_i(Y_i - \bar{Y})
\begin{aligned}[t] & = -\sum_{i = 1}^n X_i(\hat{\beta_1}\bar{X} - \hat{\beta_1} X_i) = \sum_{i = 1}^n X_i(\hat{\beta_1} X_i - \hat{\beta_1}\bar{X})\\
& = \hat{\beta_1}\sum_{i = 1}^n X_i( X_i - \bar{X})
\end{aligned} \\
&\rightarrow \hat{\beta_1} = \dfrac{\sum\limits_{i = 1}^n X_i(Y_i - \bar{Y})}{\sum\limits_{i = 1}^n X_i( X_i - \bar{X})}
\end{align*}
\end{document}