对齐方程式并删除方程式标签

对齐方程式并删除方程式标签

我有代码:

\begin{flalign} 
&f_1(y_i; \boldsymbol{\theta}_1) = \lambda e^{-\lambda y_i} \\
&l_1(\boldsymbol{\theta}_1; \textbf{y}, \textbf{x}) = `r num.not.censored` 
  \log{(\lambda)} - \lambda \sum_{i=1}^{`r num.data`} y_i \\
&f_2(y_i; x_i, \boldsymbol{\theta}_2) = e^{\beta_1 + \beta_2 x_i} 
  \exp{(-e^{\beta_1 + \beta_2 x_i}y_i)} \\
&l_2(\boldsymbol{\theta}_2; \textbf{y}, \textbf{x}) = 
  \sum_{i=1}^{`r num.not.censored`} (\beta_1 + \beta_2 x_i) 
 -\sum_{i=1}^{`r num.data`} (e^{\beta_1 + \beta_2 x_i}y_i) \\
&f_3(y_i; x_i, \boldsymbol{\theta}_3) = \frac{1}{\sqrt{2\pi\sigma^2}} 
   \exp{\bigg(\frac{-(y_i - (\gamma_1 + \gamma_2 x_i))^2}{2\sigma^2}\bigg)} \\
&l_3(\boldsymbol{\theta}_3; \textbf{y}, \textbf{x}) = - 28 
   \log(2 \pi \sigma^2) - \sum_{i=1}^{`r num.not.censored`} 
   \bigg(\frac{(y_i - (\gamma_1 + \gamma_2 x_i))^2}{2 \sigma^2}\bigg)
   \space + \\ 
&\sum_{i=`r num.not.censored + 1`}^{`r num.data`} \log 
   \bigg(\frac{1}{2} - \frac{1}{2}\text{erf}\Big(\frac{y_i - 
   (\gamma_1 + \gamma_2 x_i)}{\sigma \sqrt{2}}\Big)\bigg)
\end{flalign}

其呈现形式为:

enter image description here

我怎样才能将第 7 行向右移动,以便它从第 6 行的等号开始?

我还想删除方程 (7) 标签,因为它仍然是方程 (6) 的一部分。

谢谢,

杰克

答案1

您似乎想要的是fleqn选项,而不是flalign

\documentclass{article}
\usepackage[fleqn]{amsmath}
\usepackage{bm}

\DeclareMathOperator{\erf}{erf}

\begin{document}

\begin{gather}
f_1(y_i; \bm{\theta}_1) = \lambda e^{-\lambda y_i} \\
l_1(\bm{\theta}_1; \mathbf{y}, \mathbf{x}) = 56 
  \log{(\lambda)} - \lambda \sum_{i=1}^{75} y_i \\
f_2(y_i; x_i, \bm{\theta}_2) = e^{\beta_1 + \beta_2 x_i} 
  \exp{(-e^{\beta_1 + \beta_2 x_i}y_i)} \\
l_2(\bm{\theta}_2; \mathbf{y}, \mathbf{x}) = 
  \sum_{i=1}^{56} (\beta_1 + \beta_2 x_i) 
 -\sum_{i=1}^{75} (e^{\beta_1 + \beta_2 x_i}y_i) \\
f_3(y_i; x_i, \bm{\theta}_3) = \frac{1}{\sqrt{2\pi\sigma^2}} 
   \exp{\biggl(\frac{-(y_i - (\gamma_1 + \gamma_2 x_i))^2}{2\sigma^2}\biggr)} \\
\begin{split}
l_3(\bm{\theta}_3; \mathbf{y}, \mathbf{x}) 
 ={}&{-}28\log(2 \pi \sigma^2) - \sum_{i=1}^{56} 
   \biggl(\frac{(y_i - (\gamma_1 + \gamma_2 x_i))^2}{2 \sigma^2}\biggr)
   \\ 
 &+\sum_{i=57}^{75} \log 
   \biggl(\frac{1}{2} - \frac{1}{2}\erf\Bigl(\frac{y_i - 
   (\gamma_1 + \gamma_2 x_i)}{\sigma \sqrt{2}}\Bigr)\biggr)
\end{split}
\end{gather}

\end{document}

enter image description here

您可以轻松地将对齐方式更改为等号:

\documentclass{article}
\usepackage[fleqn]{amsmath}
\usepackage{bm}

\DeclareMathOperator{\erf}{erf}

\begin{document}

\begin{align}
f_1(y_i; \bm{\theta}_1) &= \lambda e^{-\lambda y_i} \\
l_1(\bm{\theta}_1; \mathbf{y}, \mathbf{x}) &= 56 
  \log{(\lambda)} - \lambda \sum_{i=1}^{75} y_i \\
f_2(y_i; x_i, \bm{\theta}_2) &= e^{\beta_1 + \beta_2 x_i} 
  \exp{(-e^{\beta_1 + \beta_2 x_i}y_i)} \\
l_2(\bm{\theta}_2; \mathbf{y}, \mathbf{x}) &= 
  \sum_{i=1}^{56} (\beta_1 + \beta_2 x_i) 
 -\sum_{i=1}^{75} (e^{\beta_1 + \beta_2 x_i}y_i) \\
f_3(y_i; x_i, \bm{\theta}_3) &= \frac{1}{\sqrt{2\pi\sigma^2}} 
   \exp{\biggl(\frac{-(y_i - (\gamma_1 + \gamma_2 x_i))^2}{2\sigma^2}\biggr)} \\
\begin{split}
l_3(\bm{\theta}_3; \mathbf{y}, \mathbf{x}) 
 &=-28\log(2 \pi \sigma^2) - \sum_{i=1}^{56} 
   \biggl(\frac{(y_i - (\gamma_1 + \gamma_2 x_i))^2}{2 \sigma^2}\biggr)
   \\ 
 &\mathrel{\hphantom{=}}+\sum_{i=57}^{75} \log 
   \biggl(\frac{1}{2} - \frac{1}{2}\erf\Bigl(\frac{y_i - 
   (\gamma_1 + \gamma_2 x_i)}{\sigma \sqrt{2}}\Bigr)\biggr)
\end{split}
\end{align}

\end{document}

enter image description here

需要注意几点。

  1. \boldsymbol已被弃用,并且\bm(与bm包一起)是首选。

  2. 所有\textbf命令都应该是\mathbf(在斜体上下文中,例如定理陈述,字母将以斜体排版)。

  3. \text{erf}应该定义一个合适的运算符\DeclareMathOperator(理由与前面相同)。

答案2

您将对齐符号放置在&了不该在的位置,这样就可以用来\notag抑制数字。

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{flalign} 
f_1(y_i; \boldsymbol{\theta}_1) & = \lambda e^{-\lambda y_i} \\
l_1(\boldsymbol{\theta}_1; \textbf{y}, \textbf{x}) & = `r num.not.censored` 
\log{(\lambda)} - \lambda \sum_{i=1}^{`r num.data`} y_i \\
f_2(y_i; x_i, \boldsymbol{\theta}_2) & = e^{\beta_1 + \beta_2 x_i} \exp{(- 
e^{\beta_1 + \beta_2 x_i}y_i)} \\
l_2(\boldsymbol{\theta}_2; \textbf{y}, \textbf{x}) & = \sum_{i=1}^{`r 
num.not.censored`} (\beta_1 + \beta_2 x_i) - \sum_{i=1}^{`r num.data`} 
(e^{\beta_1 + \beta_2 x_i}y_i) \\
f_3(y_i; x_i, \boldsymbol{\theta}_3) & = \frac{1}{\sqrt{2\pi\sigma^2}} 
\exp{\bigg(\frac{-(y_i - (\gamma_1 + \gamma_2 x_i))^2}{2\sigma^2}\bigg)} \\
l_3(\boldsymbol{\theta}_3; \textbf{y}, \textbf{x}) & = - 28 \log(2 \pi 
\sigma^2) - \sum_{i=1}^{`r num.not.censored`} \bigg(\frac{(y_i - (\gamma_1 + 
\gamma_2 x_i))^2}{2 \sigma^2}\bigg)\space + \notag\\ 
&\sum_{i=`r num.not.censored 
+ 1`}^{`r num.data`} \log \bigg(\frac{1}{2} - \frac{1} 
{2}\text{erf}\Big(\frac{y_i - (\gamma_1 + \gamma_2 x_i)}{\sigma 
\sqrt{2}}\Big)\bigg)
\end{flalign}
\end{document}

答案3

标准align环境(其中所有方程式都与符号对齐=)至少可以像flalign环境一样工作。

请注意,我将所有 的实例替换为r num.not.censored56并将 的所有实例替换r num.data75。通过与您发布的屏幕截图进行交叉检查,这似乎是合理的。

enter image description here

\documentclass{article}
\usepackage{amsmath}
\DeclareMathOperator{\erf}{erf}

\begin{document}
\begin{align}
f_1(y_i; \boldsymbol{\theta}_1) 
   &= \lambda e^{-\lambda y_i} \\
l_1(\boldsymbol{\theta}_1; \mathbf{y}, \mathbf{x}) 
   &= 56\log{(\lambda)} - \lambda \sum_{i=1}^{75} y_i \\
f_2(y_i; x_i, \boldsymbol{\theta}_2) 
   &= e^{\beta_1 + \beta_2 x_i} \exp{(-e^{\beta_1 + \beta_2 x_i}y_i)} \\
l_2(\boldsymbol{\theta}_2; \mathbf{y}, mathbf{x}) 
   &= \sum_{i=1}^{56} (\beta_1 + \beta_2 x_i)
     -\sum_{i=1}^{75} (e^{\beta_1 + \beta_2 x_i}y_i) \\
f_3(y_i; x_i, \boldsymbol{\theta}_3) 
   &= \frac{1}{\sqrt{2\pi\sigma^2}} 
      \exp{\biggl(\frac{-(y_i - (\gamma_1 + 
      \gamma_2 x_i))^2}{2\sigma^2}\biggr)} \\
l_3(\boldsymbol{\theta}_3; \mathbf{y}, \mathbf{x}) 
   &= - 28 \log(2 \pi \sigma^2) 
      - \sum_{i=1}^{56} \biggl(\frac{(y_i - 
      (\gamma_1 + \gamma_2 x_i))^2}{2 \sigma^2}\biggr) \\
   &\quad +\sum_{i=57}^{75} \log
      \biggl(\frac{1}{2} - \frac{1}{2}\erf \Bigl(\frac{y_i - 
      (\gamma_1 + \gamma_2 x_i)}{\sigma \sqrt{2}}\Bigr) \biggr) \notag
\end{align}
\end{document} 

相关内容