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

时间:2022-02-04 06:19:11

I'm having some difficulty left aligning equations in R Markdown (i.e. putting the equation on the far left side of page, and aligning subsequent lines). I've generally determined that I want to set the [fleqn] option in the amsmath package to left align all equations, but putting the following in my YAML header gives an error

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

'Option * for package amsmath'

'amsmath包的选项冲突'

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

A section from my 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}
$$

Thanks

谢谢

3 个解决方案

#1


5  

Try using $...$ instead of $$...$$.

尝试使用$ ... $而不是$$ ... $$。

In the case of $$...$$ in Rmarkdown is center aligned by default

在$$ ...的情况下,Rmarkdown中的$$默认为居中对齐

#2


2  

This question has already been asked here: R Markdown Math Equation Allignment

这里已经提出了这个问题:R Markdown Math Equation Allignment

The below works for me:

以下对我有用:

$\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  

$ 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} $

#1


5  

Try using $...$ instead of $$...$$.

尝试使用$ ... $而不是$$ ... $$。

In the case of $$...$$ in Rmarkdown is center aligned by default

在$$ ...的情况下,Rmarkdown中的$$默认为居中对齐

#2


2  

This question has already been asked here: R Markdown Math Equation Allignment

这里已经提出了这个问题:R Markdown Math Equation Allignment

The below works for me:

以下对我有用:

$\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  

$ 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} $