繁体   English   中英

从 Rmarkdown 编织 PDF,每页一张图像,垂直居中

[英]Knit PDF from Rmarkdown with one image per page, vertically centered

我有数百张图像,我想将它们编织到来自 Rmarkdown 的单个 pdf 文件中。 我希望每页只有一个图像,并且每个图像在页面上水平和垂直居中。 我一直在玩 kable package 几个小时试图完成,但没有运气。 谢谢您的帮助。

这是一组要使用的示例图像:

filenames <- structure(list(img_url = c("https://images.freeimages.com/images/large-previews/ce3/puppies-1-1308839.jpg", 
"https://images.freeimages.com/images/large-previews/006/young-dachshund-1362378.jpg", 
"https://images.freeimages.com/images/large-previews/20c/my-puppy-maggie-1362787.jpg"
)), row.names = c(NA, -3L), class = c("tbl_df", "tbl", "data.frame"
))

您可以使用glue package 在每个图像周围添加一些 LaTeX,这应该可以满足您的需求。

glue允许您将变量直接放入字符串中,然后您可以使用 `results = 'asis' 块选项将其合并到编织文件中。

---
title: "One Image Per Page"
output: pdf_document
---

```{r one-per-page, results = 'asis', echo = FALSE}
library("glue")

# full path to all image files, URLs should work too
image_path_list <- c("/path/image1.jpg",
                     "/path/image2.jpg")

# create LaTeX output, alter the glue open delimiter to avoid conflict
glue('\\vspace*{\\fill}\n\\begin{center}\n\\includegraphics{{(image_path_list}}\n\\end{center}\n\\vspace*{\\fill}\n\\newpage\n', .open = "{(")

```

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM