本文介绍了Bookdown不会在输出pdf中呈现图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在RStudio的bookdown-package附带的示例index.rmd文件中包含一个图像. (新建项目->使用预订的图书项目)然后,我简单地将以下代码附加到R代码块中.

I'm trying to include an image in the example index.rmd file that comes with the bookdown-package within RStudio. (New Project -> Book Project using bookdown)I then simply appended the following code within an R code-chunk.

```{r}
knitr::include_graphics("png_logo.png")
```

单独运行代码块会产生预期的输出(如图所示).但是,如果我在终端中使用以下命令:bookdown::render_book("index.Rmd", "bookdown::pdf_book")会生成一个pdf文件,其中不包含图片,而是空白.

Running the code chunk on its own produces the expected output (shows figure).However, if I use the following command in the terminal:bookdown::render_book("index.Rmd", "bookdown::pdf_book")a pdf-file is produced, that doesn't contain the image but a blank space.

我打开了一个空白的.rmd文件,粘贴了代码块,然后使用编织按钮进行了检查,这是否是一个全局问题.但是,编织测试文件会产生预期的输出

I opened up a blank .rmd file, pasted the code chunk and used the knit-button to check, wether this was a global problem. However, knitting the test file produced the expected output

---
title: "Untitled"
output:
  pdf_document: default
---
# simple test file

```{r}
knitr::include_graphics("png_logo.png")
```

这使我相信,这是与书本有关的问题.包括相应的LaTeX代码\includegraphics{png_logo.png}在按书本创建的pdf中产生了相同的空白,但与编织的.rmd文件配合正常.

This leads me to believe, that this is a bookdown-related issue.Including the corresponding LaTeX code \includegraphics{png_logo.png} produced the same blank space in the bookdown-created pdf but works fine with the knitted .rmd file.

我在SO上找到了类似的问题( knitr ::书本中的include_graphics不会呈现图像),并确保文件名和文件路径均不包含空格. TinyTex和tinytex软件包已安装.没有安装其他LaTeX发行版(尽管以前已安装MikTeX).

I found a similar issue on SO (knitr::include_graphics in bookdown, is not rendering the image) and made sure neither the file name nor the path to the file contains blank spaces. TinyTex and the tinytex package are installed. No other LaTeX distribution is installed (though MikTeX was previously installed).

我们将不胜感激!

在另一台计算机上尝试bookdown::render_book("index.Rmd", "bookdown::pdf_book")命令也无法渲染图像.

Trying the bookdown::render_book("index.Rmd", "bookdown::pdf_book") command on another machine somehow didn't render the image either.

我尝试了bookdown::render_book("index.Rmd", "bookdown::gitbook")bookdown::render_book("index.Rmd", "bookdown::pdf_document2")两者都产生了预期的输出.

I tried out bookdown::render_book("index.Rmd", "bookdown::gitbook")and bookdown::render_book("index.Rmd", "bookdown::pdf_document2")and both produced the expected output.

但是,使用任何一种解决方法都不适用于我的用例,因为我试图使用由同事生成的报告模板.因此,我的目标是得到bookdown::render_book("index.Rmd", "bookdown::pdf_book")跑步.帮助将不胜感激!

However, using either workaround is not applicable to my use-case as I am trying to use a report template produced by a colleague. Thus, my aim is to get bookdown::render_book("index.Rmd", "bookdown::pdf_book")running. Help would still be greatly appreciated!

推荐答案

我遇到了同样的问题.一种解决方案终于奏效了:将latex_engine更改为pdflatex而不是xelatex.在_output.yml文件中.

I ran into the same problem. One solution finally seems to work: Change the latex_engine to pdflatex instead of xelatex. It's in the _output.yml file.

bookdown::pdf_book:
  latex_engine: pdflatex

编辑:似乎xelatex需要更新,运行

Edit: It seems that xelatex needed to be updated, it works again now after running

tinytex::tlmgr_update()

这篇关于Bookdown不会在输出pdf中呈现图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 17:57