使用xaringan包做了幻灯片,html格式显示完好,然而,打印为pdf后,却发现有很多的图片无法显示。当时临近会议,惊得我一身冷汗,短时间内又无法解决。情急之下只好将网页版幻灯片截图下来,插入PDF版中。暂时化解危机。
今天,又反复测试了一下,发现了问题。当图片out.width超出范围后,html格式可以正常显示,但是转成pdf(Google Chrome打印)时图片无法显示。
知道这问题后下次就可避免,比如out.width设置不要太大。但是我想知道,有没有更好的方法或者建议呢?
xaringan测试代码如下:
---
title: "幻灯忍者"
subtitle: "写轮眼"
author: "xxx"
institute: "RStudio, PBC"
date: "2016/12/12"
output:
xaringan::moon_reader:
css: [default, zh-CN.css]
lib_dir: libs
nature:
ratio: "16:9"
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
---
```{r include=FALSE}
jpeg("test.jpg", width = 1600, height = 900)
par(bg=grey(7/8))
plot(0:100)
dev.off()
```
测试90%
```{r echo=FALSE, out.width = "90%"}
knitr::include_graphics("test.jpg")
```
---
测试92%
```{r echo=FALSE, out.width = "92%"}
knitr::include_graphics("test.jpg")
```
---
测试96%
```{r echo=FALSE, out.width = "96%"}
knitr::include_graphics("test.jpg")
```
---
测试100%
```{r echo=FALSE, out.width = "100%"}
knitr::include_graphics("test.jpg")
```
---
测试49%+49%
```{r echo=FALSE, out.width = "49%"}
knitr::include_graphics("test.jpg")
```
```{r echo=FALSE, out.width = "49%"}
knitr::include_graphics("test.jpg")
```
---
测试50%+50%
```{r echo=FALSE, out.width = "50%"}
knitr::include_graphics("test.jpg")
```
```{r echo=FALSE, out.width = "50%"}
knitr::include_graphics("test.jpg")
```
我的运行环境如下:
> sessionInfo()
R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)
Matrix products: default
locale:
[1] LC_COLLATE=Chinese (Simplified)_China.utf8
[2] LC_CTYPE=C
[3] LC_MONETARY=Chinese (Simplified)_China.utf8
[4] LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_China.utf8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] Rcpp_1.0.8.3 compiler_4.2.1 later_1.3.0 remotes_2.4.2
[5] tools_4.2.1 digest_0.6.29 jsonlite_1.8.0 evaluate_0.15
[9] lifecycle_1.0.1 viridisLite_0.4.0 rlang_1.0.2 cli_3.3.0
[13] rstudioapi_0.13 yaml_2.3.5 pagedown_0.18 xfun_0.31
[17] fastmap_1.1.0 kableExtra_1.3.4 httr_1.4.3 stringr_1.4.0
[21] xml2_1.3.3 knitr_1.39 htmlwidgets_1.5.4 systemfonts_1.0.4
[25] websocket_1.4.1 DT_0.24 webshot_0.5.3 svglite_2.1.0
[29] glue_1.6.2 R6_2.5.1 processx_3.5.3 rmarkdown_2.14
[33] xaringan_0.26 magrittr_2.0.3 servr_0.24 ps_1.7.0
[37] scales_1.2.0 promises_1.2.0.1 htmltools_0.5.2 rvest_1.0.2
[41] mime_0.12 colorspace_2.0-3 httpuv_1.6.5 stringi_1.7.6
[45] munsell_0.5.0