r - RMarkdown Beamer make slide titles and add figures in loop
问题描述
I am new to RMarkdown and Beamer. I am trying to make a set of slides where each slide contains a JPG. I have a dozen to loop through. How do I set this up in a loop?
Here is the RMD file:
---
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")
```
I know I can put the slide titles and figure paths into a data frame, but I am not sure how to do this inside RMarkdown and how to loop through it to build the slide titles and insert the images.
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)
Updated Based on Accepted Answer
Below is what I ended up using for my Rmd. This page explains the basics of the xmpmulti
package.
For this set up, my RMD is in one folder; the images are one folder up (../
) and then in a folder called temp (../temp/
). The images in this folder are named test-1.png
, test-2.png
, etc.
---
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
解决方案
假设您的图像被命名pic-1.png
等,那么 beamer 有一种自动方式通过xmpmulti
包循环图像:
---
title: 'slideshow'
output:
beamer_presentation:
theme: "AnnArbor"
keep_tex: true
header-includes:
- \usepackage{xmpmulti}
---
# Introduction
## Blah
- Text
- Here
- Etc.
```{=latex}
\end{frame}
\section{Images}
\begin{frame}
\frametitle<1>{picture 1}
\frametitle<2>{picture 2}
\frametitle<3>{picture 3}
\centering
\multiinclude[format=png,start=1,end=3,graphics={width=.6\textwidth}]{pic}
\end{frame}
\begin{frame}
```
some test
推荐阅读
- android - 出现错误:覆盖方法应该调用 super.onActivityResult
- uitableview - 表单中的 SwiftUI Pickers 出错:UITableView 被告知在不位于视图层次结构中的情况下布局其可见单元格和其他内容
- firebase - 在本地窗口上调试 firebase
- algorithm - 如何多次更新树的节点?
- javascript - 找不到模块:无法解析“./node_modules/@material-ui/core/IconButton”
- python - 为什么我的 Django robots.txt 在开发中有效,但在生产中返回服务器错误 500?
- javascript - 为什么我的 addEventListener 不能使用我的 laravel 刀片文件
- ios - 语言默认为英语而不是法语为法语法语
- c# - 保存许多属于文件的标签的推荐数据格式/结构?
- php - PHP 调用 Graphdb 在 shell 中工作,而不是在浏览器中