如何在R Markdown中保留对齐乳胶方程式?

时间:2015-02-26 16:59:19

标签: r latex rstudio r-markdown

我在R Markdown中对齐方程式时遇到了一些困难(即将等式放在页面的最左侧,并对齐后续行)。我一般都认为我想在amsmath包中设置[fleqn]选项以保持对齐所有方程式,但是将以下内容放在我的YAML标题中会出错

'包amsmath的选项冲突'

---
author: "ME"
date: "February 26, 2015"
header-includes:
  - \usepackage[fleqn]{amsmath}
output: pdf_document
---

我的文件中的一部分:

$$
\begin{aligned}
Bias(\hat{\theta})  &= E(\hat{\theta}) - \theta \\
                    &= E(2 \bar{X} -1) - \theta \\
                    &= \frac{2}{n}\sum_{i=1}^n E(X_i) -1 -\theta \\
                    &= 2E(X) - 1 - \theta \\
                    &= 2 \cdot \frac{\theta+1}{2} - 1 - \theta \\
                    &= 0 \\
\end{aligned}
$$

由于

3 个答案:

答案 0 :(得分:9)

尝试使用$...$代替$$...$$

如果Rmarkdown中的$$...$$默认为居中对齐

答案 1 :(得分:4)

此问题已在此处提出:R Markdown Math Equation Allignment

以下内容适用于我:

$\begin{aligned}
Bias(\hat{\theta})  &= E(\hat{\theta}) - \theta \\
                    &= E(2 \bar{X} -1) - \theta \\
                    &= \frac{2}{n}\sum_{i=1}^n E(X_i) -1 -\theta \\
                    &= 2E(X) - 1 - \theta \\
                    &= 2 \cdot \frac{\theta+1}{2} - 1 - \theta \\
                    &= 0 \\
\end{aligned}$

答案 2 :(得分:0)

$ L(x_{1}, x_{2}, ..., x_{n}| \mu) =  \mu * (1-\mu) $

$log (\ L(x_{1}, x_{2}, ..., x_{n}| \mu)) = h * log(\mu) + (m-h) * log(1-\mu) $

$\frac{\partial  log(\ L(x_{1}, x_{2}, ..., x_{n}| \mu)}{\partial(\mu)}  = \frac{h}{\mu} + \frac{h-m}{1-\mu} $

#### We set this to zero to find the value that maximizes the likelihood 

$\frac{h}{\mu} + \frac{h-m}{1-\mu} = 0 $

$h = m * \mu $

$\mu = \frac{h}{m} $