putting lines in multiline LaTex equations in the PDF version of an Rmarkdown file

1,537 views
Skip to first unread message

Erin Hodgess

unread,
Aug 30, 2015, 10:54:59 AM8/30/15
to knitr
Good morning!

First of all, knitr, Rmarkdown, and Rstudio are the best things since sliced bread, Coca-Cola, etc.

I have one questions, which I'm sure is an easy fix.

I am making up some lecture notes for my students.  Some like HTML, while others prefer PDF.  I like happy students.  So I am using Rmarkdown within Rstudio. 

This is on a Mac, R Version 3.2.0.

Here are the lines from the Rmarkdown file:

We will review some of the very fun and interesting concepts that we discussed on Wednesday, August 26.

We know in our hearts that the gamma probability function is the following:

\[ 
f(x) = \dfrac{\lambda^r}{\Gamma(r)} x^{r-1} e^{-\lambda x}, 
\]



Here is some more stuff



\[
E[X] = \lambda \cdot \dfrac{\Gamma(2)}{\lambda^2}
 \left \lbrack \int_0^{\infty} \dfrac{\lambda^2}{\Gamma(2)} 
x e^{-\lambda x} \; dx \right \rbrack, \\
E[X] = \lambda \cdot \dfrac{\Gamma(2)}{\lambda^2} \cdot 1, \\
E[X] = \dfrac{(2-1)!}{\lambda} = \dfrac{1}{\lambda}
\]

This works just fine when I use knitr to HTML.  However, when I use knitr to PDF, the second set puts all of the equations on one line.

What can I do to fix this, please?

I also attached the entire file for ease of use.

Thank you for any help.

Sincerely,
Erin

prob3.Rmd

Yihui Xie

unread,
Aug 30, 2015, 12:26:42 PM8/30/15
to Erin Hodgess, knitr
http://lmgtfy.com/?q=latex+equation+break+into+two+lines#

$$
\begin{split}
E[X] = \lambda \cdot \dfrac{\Gamma(2)}{\lambda^2}
\left \lbrack \int_0^{\infty} \dfrac{\lambda^2}{\Gamma(2)}
x e^{-\lambda x} \; dx \right \rbrack, \\
E[X] = \lambda \cdot \dfrac{\Gamma(2)}{\lambda^2} \cdot 1, \\
E[X] = \dfrac{(2-1)!}{\lambda} = \dfrac{1}{\lambda}
\end{split}
$$

Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Web: http://yihui.name
> --
> You received this message because you are subscribed to the Google Groups "knitr" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to knitr+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Erin Hodgess

unread,
Aug 30, 2015, 12:52:16 PM8/30/15
to Yihui Xie, knitr
This is so great!

Thank you very much!

(And my students thank you too...sort of!)

--
Erin Hodgess
Associate Professor
Department of Mathematical and Statistics
University of Houston - Downtown
mailto: erinm....@gmail.com
Reply all
Reply to author
Forward
0 new messages