28

I am writing a bunch of math equations in R Markdown inside Rstudio. And I want to align the content either to the left or center. However, seems like the align will align them to the right as default.

enter image description here

I did some google and some of them told me to use a package called ragged2e, but it did not work when I added it in. I am wondering if this should be a latex question or rmarkdown question.

Sangwin Gawande
  • 7,658
  • 8
  • 48
  • 66
B.Mr.W.
  • 18,910
  • 35
  • 114
  • 178

3 Answers3

64

I'm not quite sure what you're going for here, but line breaks, \\ go at the end of tthe line, not the beginning, and the aligmnent operator is &. So this:

$$
\begin{aligned}
 AR(p): Y_i &= c + \epsilon_i + \phi_i Y_{i-1} \dots \\
 Y_{i} &= c + \phi_i Y_{i-1} \dots
\end{aligned}
$$

produces this:

jlhoward
  • 58,004
  • 7
  • 97
  • 140
10

left align the formula

$\begin{aligned}
AR(p): Y_i &= c + \epsilon_i + \phi_i Y_{i-1} \dots \\
Y_{i} &= c + \phi_i Y_{i-1} \dots
\end{aligned}$

&...& show in the line ; $$...$$ display out;

atongsa
  • 334
  • 3
  • 10
2

Wow. That works great! Thank you for the help! This worked perfectly in R Studio Markdown. My code was in an ordered list and is as follows:

$\begin{aligned}
    \lim_{x \to \infty}\frac{2x-5}{4x^4}=0\\
    \end{aligned}$    

$\begin{aligned}
    \frac{d}{dx}\left( \int_{0}^{x}f(u)\,du\right)=f(x)\\
    \end{aligned}$
The Chez
  • 21
  • 3