问题
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")
```
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.
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")
```
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.
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).
Help would be greatly appreciated!
Edit:
Trying the bookdown::render_book("index.Rmd", "bookdown::pdf_book")
command on another machine somehow didn't render the image either.
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.
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!
回答1:
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
Edit: It seems that xelatex
needed to be updated, it works again now after running
tinytex::tlmgr_update()
来源:https://stackoverflow.com/questions/58398191/bookdown-does-not-render-image-in-output-pdf