【发布时间】:2021-10-08 06:07:31
【问题描述】:
我是 RMarkdown 和 Beamer 的新手。我正在尝试制作一组幻灯片,其中每张幻灯片都包含一个 JPG。我有十几个要循环。如何循环设置?
这里是 RMD 文件:
---
title: 'slideshow'
output:
beamer_presentation:
theme: "AnnArbor"
---
# Introduction
## Blah
- Text
- Here
- Etc.
# Images
## pic_1
```{r echo=FALSE, out.width = '100%'}
knitr::include_graphics("../images/modelA_pic_1.jpg")
```
## pic_2
```{r echo=FALSE, out.width = '100%'}
knitr::include_graphics("../images/modelA_pic_2.jpg")
```
## pic_3
```{r echo=FALSE, out.width = '100%'}
knitr::include_graphics("../images/modelA_pic_3.jpg")
```
## pic_4
```{r echo=FALSE, out.width = '100%'}
knitr::include_graphics("../images/modelA_pic_4.jpg")
```
我知道我可以将幻灯片标题和图形路径放入数据框中,但我不确定如何在 RMarkdown 中执行此操作,以及如何循环通过它来构建幻灯片标题并插入图像。
title <- c('pic_1', 'pic_2', 'pic_3', 'pic_4')
fpath <- c('modelA_pic_1.jpg', 'modelA_pic_2.jpg', 'modelA_pic_3.jpg', 'modelA_pic_4.jpg')
fpath <- paste0("../images/", fpath)
myfiles <- data.frame(title, fpath)
根据接受的答案更新
以下是我最终用于 Rmd 的内容。 This page 解释了 xmpmulti 包的基础知识。
对于此设置,我的 RMD 位于一个文件夹中;这些图像位于一个文件夹中 (../),然后位于一个名为 temp (../temp/) 的文件夹中。此文件夹中的图像命名为test-1.png、test-2.png 等。
---
title: 'slideshow'
output:
beamer_presentation:
theme: "AnnArbor"
header-includes:
- \usepackage{xmpmulti}
---
# Introduction
## Blah
- Text
- Here
- Etc.
```{=latex}
\end{frame}
\section{Images}
\begin{frame}
\frametitle<1>{picture 1}
\frametitle<2>{picture 2}
\centering
\multiinclude[format=png,start=1,end=2,graphics={width=1\textwidth}]{../temp/test}
\end{frame}
\begin{frame}
```
some test
【问题讨论】:
标签: r latex r-markdown beamer presentation