使用Pander + Knitr创建PDf文件的问题:将带有标题的表格放置在地图上并直接彼此相邻时出错 [英] Issue with creating PDf file with Pander+Knitr: Error when putting table with caption and plot directly next to each other
问题描述
我的pander(+ knitr)有一个可重现的错误: 将带有标题的表格和图表直接相互放置时,我无法创建PDF文件.我在Windows上使用pander 0.5.1,knitr 1.7,R版本3.1.1,Miktex + RStudio.
I have a reproducible error with pander (+ knitr): When a table with caption and a plot is put directly to each other, I cannot create a PDF File. I use pander 0.5.1, knitr 1.7, R version 3.1.1, Miktex + RStudio on Windows.
因此,以下内容将产生错误(另请参见下面的我的错误和非错误列表"):
So the following will produce the error (see also my List of errors and non-errors below):
```{r, echo=FALSE, eval=TRUE}
pander(cor(cars), caption="Whatever" ) # or some other captioned table
hist(cars$speed) #or some other plot
```
pandoc.exe: Error producing PDF from TeX source Fehler: pandoc document conversion failed with error 43 Zus�tzlich: Warnmeldung: Ausf�hrung von Kommando '"C:/Program Files/RStudio/bin/pandoc/pandoc" Teste_markdown_Cor+Hist.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures
--output Teste_markdown_Cor+Hist.pdf --template "C:\Users\jbothe\Documents\R\win-library\3.1\rmarkdown\rmd\latex\default.tex"
--highlight-style tango --latex-engine pdflatex --variable "geometry:margin=1in"' ergab Status 43 Ausf�hrung angehalten
当我手动复制并粘贴pander的输出时,问题似乎出在情节之前是空行:
When I manually copy&paste the output from pander, the issue seems to be with an empty line before the plot:
不工作:
--------------------------
speed dist
----------- ------- ------
**speed** 1 0.8069
**dist** 0.8069 1
--------------------------
Table: K
```{r, echo=FALSE, eval=FALSE}
hist(cars$speed)
```
工作无误
--------------------------
speed dist
----------- ------- ------
**speed** 1 0.8069
**dist** 0.8069 1
--------------------------
Table: K
```{r, echo=FALSE, eval=FALSE}
hist(cars$speed)
```
但是,即使我在平移器和绘图之间的代码块中放置了不同的空行,错误仍然存在
But even if I put different empty lines in the code-chunk between pander and the plot, the error continues
列表:
---
title: "Teste Cor + Hist"
output: pdf_document
---
# Does not work
```{r, echo=FALSE}
library(pander)
```
Does not work:
```{r, echo=FALSE, eval=TRUE}
pander(cor(cars), caption="Korrelationen" )
hist(cars$speed)
```
Does not work :
```{r, echo=FALSE, eval=FALSE}
pander(cor(cars), caption="Korrelationen" )
plot(cars)
```
Does not work:
```{r, echo=FALSE, eval=FALSE}
pander(cor(cars), caption="K" )
plot(cars)
```
Does not work:
```{r, echo=FALSE, result='asis', comment=NA, eval=FALSE}
pander(cor(cars), caption="Korrelationen" )
#several line breaks
hist(cars$speed)
```
Doesnt Work:
--------------------------
speed dist
----------- ------- ------
**speed** 1 0.8069
**dist** 0.8069 1
--------------------------
Table: K
```{r, echo=FALSE, eval=FALSE}
hist(cars$speed)
```
# Works without Error
--------------------------
speed dist
----------- ------- ------
**speed** 1 0.8069
**dist** 0.8069 1
--------------------------
Table: K
```{r, echo=FALSE, eval=FALSE}
hist(cars$speed)
```
Works:
```{r, echo=FALSE, eval=TRUE}
cat("Korrelationen")
hist(cars$speed)
```
Works:
```{r, echo=FALSE, eval=TRUE}
pander(cor(cars), caption="Korrelationen" )
cat("Korrelationen")
hist(cars$speed)
```
Works:
```{r, echo=FALSE, eval=TRUE}
cat("table: Korrelationen")
hist(cars$speed)
```
Works:
```{r, echo=FALSE, result='asis', comment=NA, eval=TRUE}
pander(cor(cars), caption="Korrelationen" )
cat("table: Korrelationen")
hist(cars$speed)
```
推荐答案
我找到了一种解决方法,手动在字幕的末尾添加了换行符.但是我仍然认为应该将其视为错误?!?
Works:
```{r, echo=FALSE, eval=TRUE}
pander(cor(cars), caption="whatever text\n" )
hist(cars$speed)
```
这篇关于使用Pander + Knitr创建PDf文件的问题:将带有标题的表格放置在地图上并直接彼此相邻时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!