【发布时间】:2017-03-26 12:28:10
【问题描述】:
我正在尝试在 r markdown 中使用 LaTeX grid-system 包。有谁知道这是怎么做到的吗?当制作包含纯文本的单元格时一切顺利,但当尝试包含 r 块时,我收到此错误:
output file: testtest.knit.md
! You can't use `macro parameter character #' in horizontal mode.
\gridsystem@cellcontent0 ...(cars) ``` \par ``` ##
## speed dist #### Min. : ...
l.106 \end{Row}
pandoc.exe: Error producing PDF
Error: pandoc document conversion failed with error 43
In addition: Warning message:
running command '"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS testtest.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output testtest.pdf --template "C:\Users\pc\Documents\R\win-library\3.3\rmarkdown\rmd\latex\default-1.17.0.2.tex" --highlight-style tango --latex-engine xelatex --variable graphics=yes --variable "geometry:margin=1in"' had status 43
Execution halted
我使用了这个代码:
---
output:
pdf_document:
latex_engine: xelatex
header-includes:
- \usepackage{grid-system}
---
\begin{Row}%
\begin{Cell}{2}
```{r cars}
summary(cars)
```
\end{Cell}
\begin{Cell}{1}
Some text using 1/3 of the width.
\end{Cell}
\end{Row}
更新:
cmets 中提到的解决方案comment=">" 适用于上面的代码,但在尝试包含绘图时,如下所示:
---
output:
pdf_document:
latex_engine: xelatex
header-includes:
- \usepackage{grid-system}
---
\begin{Row}
\begin{Cell}{5}
```{r, comment='>'}
plot(pressure)
```
\end{Cell}
\begin{Cell}{1}
Some text using 1/6 of the width.
\end{Cell}
\end{Row}
它会产生这个错误:
! Missing $ inserted.
<inserted text>
$
l.98 \end{Row}
【问题讨论】:
-
最简单的方法是避免散列。尝试使用
comment = '>'为您的块使用另一个字符作为 cmets。 -
感谢您的回复。我不确定我是否明白你的意思。作为一个块选项?
-
{r cars, comment='>'}。或者您通过调用opts_chunk$set(comment='>')全局设置它(适用于所有块) -
它有效!再次感谢。如果您将此作为答案,我会接受。如果我用
plot(pressure替换summary(cars),我仍然得到一个错误。关于那个解决方案的任何想法?
标签: r latex r-markdown grid-system