[英]Why does \\ not break lines in this R markdown example?
The file ./vignettes/foo.Rmd in an R package contains: R 包中的文件 ./vignettes/foo.Rmd 包含:
---
title: Foo
author: Marius Hofert
vignette: >
%\VignetteEngine{knitr::rmarkdown}
%\VignetteIndexEntry{Foo}
---
\[
\begin{align}
X_t &= \mu_t + \sigma_t Z_t\\
\mu_t &= \mu + \sum_{k=1}^{p_1} \phi_k (X_{t-k}-\mu) +
\sum_{k=1}^{q_1} \theta_k (X_{t-k}-\mu_{t-k})\sigma_t^2\\
&= \alpha_0 + \sum_{k=1}^{p_2} \alpha_k (X_{t-k}-\mu_{t-k})^2 +
\sum_{k=1}^{q_2} \beta_k \sigma_{t-k}^2.
\end{align}
\]
However, this is the output:但是,这是输出:
So the line breaks (via \\\\
) seem to be ignored.所以换行符(通过
\\\\
)似乎被忽略了。 Why?为什么?
In my R version it crashed when I tried to include amsmath
.在我的 R 版本中,当我尝试包含
amsmath
时它崩溃了。 Somehow it seems to be already loaded.不知何故,它似乎已经加载。
As I already mentioned in the comment omitting \\[ ... \\]
worked for the code below.正如我在注释中已经提到的,省略
\\[ ... \\]
适用于下面的代码。
---
title: "Document title"
author: "Author's name"
output: pdf_document
---
\begin{align}
X_t &= \mu_t + \sigma_t Z_t\\
\mu_t &= \mu + \sum_{k=1}^{p_1} \phi_k (X_{t-k}-\mu) +
\sum_{k=1}^{q_1} \theta_k (X_{t-k}-\mu_{t-k})\sigma_t^2\\
&= \alpha_0 + \sum_{k=1}^{p_2} \alpha_k (X_{t-k}-\mu_{t-k})^2 +
\sum_{k=1}^{q_2} \beta_k \sigma_{t-k}^2.
\end{align}
The following worked:以下工作:
---
title: Foo
author: Marius Hofert
vignette: >
%\VignetteEngine{knitr::rmarkdown}
%\VignetteIndexEntry{Foo}
---
\[
\begin{align}
X_t &= \mu_t + \sigma_t Z_t\\\\
\mu_t &= \mu + \sum_{k=1}^{p_1} \phi_k (X_{t-k}-\mu) +
\sum_{k=1}^{q_1} \theta_k (X_{t-k}-\mu_{t-k})\sigma_t^2\\\\
&= \alpha_0 + \sum_{k=1}^{p_2} \alpha_k (X_{t-k}-\mu_{t-k})^2 +
\sum_{k=1}^{q_2} \beta_k \sigma_{t-k}^2.
\end{align}
\]
What I found out (much) later is that I was missing the R package rmarkdown
.我后来(很久)发现的是我错过了 R 包
rmarkdown
。 With that, one indeed doesn't need to escape backslashes and only needs to provide \\begin{align}..\\end{align}
(without \\[...\\]
)有了这个,一个人确实不需要转义反斜杠,只需要提供
\\begin{align}..\\end{align}
(没有\\[...\\]
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.