2017-03-26 35 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控制文件夾的名稱。這些圖是使用塊名命名的。