Align environment in R Markdown which works for bo

2019-07-12 10:00发布

QUESTION:

In R Markdown, what is the right way to add a LaTeX align-like environment (with and without equation numbering) which will compile and display for both docx and pdf output?

DETAIL:

Option 1 below is what I'm going with. But I'd still like the option to have equation numbering and not give up that functionality when I move between docx and pdf output.

This compiles and displays in both docx and pdf output. Hooray! But what if I want equation numbering?

\[
\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}
\]

This will not compile for pdf or docx output.

\[
\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*}
\]

These compile for both docx and pdf output. But these only display in pdf output.

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

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

These will compile and display for docx output. But these will not even compile for pdf output.

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

\[
\begin{align*}
 AR(p): Y_i &= c + \epsilon_i + \phi_i Y_{i-1} \dots \\
 Y_{i} &= c + \phi_i Y_{i-1} \dots
\end{align*}
\]

1条回答
SAY GOODBYE
2楼-- · 2019-07-12 10:23

The following works for me:

---
output:
  bookdown::pdf_document2: default
  bookdown::word_document2: default
  bookdown::html_document2: default
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

\begin{equation*}
\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}
\end{equation*}

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

I am using the *-environments to get unnumbered equations in PDF. To get numbererd equations, you should use the environments without * and add labels.

查看更多
登录 后发表回答