【问题标题】:RMarkdown Beamer make slide titles and add figures in loopRMarkdown Beamer 制作幻灯片标题并循环添加数字
【发布时间】: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.pngtest-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


    【解决方案1】:

    假设您的图像被命名为 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
    

    【讨论】:

    • 感谢您的回答,这看起来应该可以,但我收到一个错误。我更新了 OP 以反映我对您的回答的尝试以及由此产生的错误
    • @a11 _ 键用于数学 - 仅用于数学。你不能在你的框架标题中使用它而不转义,例如../images/modelA\_pic\_1
    • 引号不会对不允许的字符做任何事情。使用转义的下划线,这对我来说很好:rstudio.cloud/project/2490816
    • 我进一步研究了 xmpmulti 包并让它工作,感谢您的帮助
    猜你喜欢
    • 2017-12-26
    • 2023-02-23
    • 2016-08-15
    • 2016-05-15
    • 2021-02-13
    • 2017-05-31
    • 1970-01-01
    • 1970-01-01
    • 2011-02-07
    相关资源
    最近更新 更多