Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I left align latex equations in R Markdown?

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

'Option clash for package 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

like image 469
Steve Reno Avatar asked Feb 26 '15 16:02

Steve Reno


People also ask

How do you align equations in Rmarkdown?

Aligning equations to a character This is simply done by adding a & before the aligned character in all lines.

How do you align an equation to the left in LaTeX?

For equations longer than a line use the multline environment. Insert a double backslash to set a point for the equation to be broken. The first part will be aligned to the left and the second part will be displayed in the next line and aligned to the right.

How do we align an equation in LaTeX?

The eqnarray environment lets you align equations so that, for example, all of the equals signs "=" line up. To do this, put ampersand "&" signs around the text you want LaTeX to align, e.g. Each equation can be labelled separately, just put the label command after the relevant equation.

How do I align in Markdown?

Aligning Text By default, all text in Markdown fields are aligned to the left. You can also align to the right, or center the content by wrapping the text in div tags.


2 Answers

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

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

like image 51
Lovetoken Avatar answered Sep 29 '22 07:09

Lovetoken


This question has already been asked here: 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}$
like image 20
stemgal Avatar answered Sep 29 '22 07:09

stemgal