2017-03-26 34 views
0

我试图在r markdown中使用LaTeX grid-system包。有谁知道这是怎么做到的吗?当制造细胞,包括明文一切顺利的话,而是试图包括R块,当我得到这个错误:如何在r markdown中使用LaTeX网格系统包(并将r块放在LaTeX环境中)?

output file: testtest.knit.md 

    ! You can't use `macro parameter character #' in horizontal mode. 
\[email protected] ...(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} 

更新:

上述代码中提到的解决方案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} 
+0

最简单的方法是避免哈希。尝试使用另一个字符作为评论,使用'comment ='>''作为您的组块。 –

+0

谢谢你的回应。我不确定我是否明白你的意思。作为大块选项? – rdatasculptor

+1

'{r cars,comment ='>'}'。或者你可以通过调用'opts_chunk $ set(comment ='>')' –

回答

0

有几个符号,那些在德州有特殊意义的哈希是相对于用来创建宏。因此,当您使用散列而不逃避它时,LaTex会感到困惑。 将块选项comment设置为另一个符号,如>或根本没有符号('')将更改此设置。

关于你的第二个问题,我不确定为什么在最终的pdf中包含剧情的代码翻译失败。一个解决将产生的情节和直接使用乳胶调用包含文件:

```{r cars, engine='R', echo = F, include=F, fig.path='plots/'} 
plot(pressure, col = 'blue', pch = 16) 
``` 
\includegraphics{plots/cars-1.pdf} 

您可以fig.path控制文件夹的名称。这些图是使用块名命名的。