如何在r降价中使用LaTeX网格系统包(并在LaTeX环境中放置r块)?
我试图在r markdown中使用乳胶包。有人知道怎么做吗?当创建包含纯文本的单元格时,一切都进行得很顺利,但当尝试包含r块时,我会遇到以下错误:如何在r降价中使用LaTeX网格系统包(并在LaTeX环境中放置r块)?,r,latex,r-markdown,grid-system,R,Latex,R Markdown,Grid System,我试图在r markdown中使用乳胶包。有人知道怎么做吗?当创建包含纯文本的单元格时,一切都进行得很顺利,但当尝试包含r块时,我会遇到以下错误: output file: testtest.knit.md ! You can't use `macro parameter character #' in horizontal mode. \gridsystem@cellcontent0 ...(cars) ``` \par ``` ##
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
! Missing $ inserted.
<inserted text>
$
l.98 \end{Row}
我使用了以下代码:
---
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}
更新:
注释中提到的解决方案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}
它会产生以下错误:
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
! Missing $ inserted.
<inserted text>
$
l.98 \end{Row}
!缺少插入的$。
$
l、 98\结束{Row}
有两个符号,在Tex中有特殊含义。哈希用于创建宏。因此,当您使用哈希而不转义它时,LaTex会感到困惑。
将区块选项comment
设置为另一个符号,如
或根本没有符号('
),将改变这一点
关于你的第二个问题,我不知道为什么在最终pdf中包含情节的代码翻译失败了。解决方法是生成绘图,并直接使用LaTeX调用包含文件:
```{r cars, engine='R', echo = F, include=F, fig.path='plots/'}
plot(pressure, col = 'blue', pch = 16)
```
\includegraphics{plots/cars-1.pdf}
您可以使用
fig.path
控制文件夹的名称。绘图使用块名命名。最简单的方法是避免散列。请尝试使用另一个字符作为注释,方法是使用comment='>'
作为区块。感谢您的回复。我不知道我是否明白你的意思。作为块选项?{r cars,comment='>'}
。或者通过调用opts\u chunk$set(comment='>')
对其进行全局设置(针对所有块)!再次感谢。如果你回答这个问题,我会接受的。如果我用plot(pressure
替换summary(cars)
,我仍然得到一个错误。关于这个问题的解决方案有什么想法吗?