page numbers in beamer output from R markdown

感情迁移 提交于 2021-01-29 06:20:45

问题


I am trying to add page numbers to my beamer presentation. I am using the following code in Rmarkdown (see below). The problem is that the page numbers are cut off. I have tried using geometry to adjust the dimensions but i keep getting an error message that they are incompatible. Does anyone have any ideas? I have spent hours searching for a solution.

---
title: my title
author: "me"
date: "May 05, 2016"
output: beamer_presentation
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyhead{}
- \fancyfoot{}
- \fancyfoot[R]{\thepage}
- \setbeamertemplate{footline}{\thepage}
---

Global Options
=======================================================

```{r global_options, include=FALSE}
# Setting up your workspace for standard figure output and exclusion of chunk codes, warnings, and messages unless otherwise specified:
knitr::opts_chunk$set(fig.width=6, fig.height=4, 
                      fig.path='Figs/', 
                      fig.show='asis', include=FALSE, warning=FALSE, message=FALSE)
```

```{r}
 library(knitr)
```

```{r cars, include=TRUE, echo=FALSE}
summary(cars)
```


# Including Plots


```{r pressure, echo=FALSE, include=TRUE}
plot(pressure)
```

回答1:


As @Werner already said, you should not use fancyhdr with beamer, because beamer has its own mechanism for head and footline.

The easiest way to add page numbers to a beamer presentation is to use one of the predefined templates, e.g. \setbeamertemplate{footline}[frame number]. Unfortunately it seems to be impossible to have optional arguments in rmarkdown header-includes, but one can trick rmarkdown and hide them in a file:

---
title: my title
author: "me"
date: "May 05, 2016"
output: 
  beamer_presentation:
    keep_tex: true
    includes:
      in_header: preamble.tex
---

Global Options
=======================================================

```{r global_options, include=FALSE}
# Setting up your workspace for standard figure output and exclusion of chunk codes, warnings, and messages unless otherwise specified:
knitr::opts_chunk$set(fig.width=6, fig.height=4, 
                      fig.path='Figs/', 
                      fig.show='asis', include=FALSE, warning=FALSE, message=FALSE)
```

```{r}
 library(knitr)
```

```{r cars, include=TRUE, echo=FALSE}
summary(cars)
```


# Including Plots


```{r pressure, echo=FALSE, include=TRUE}
plot(pressure)
```

and preamble.tex

\setbeamertemplate{footline}[frame number]


来源:https://stackoverflow.com/questions/37175154/page-numbers-in-beamer-output-from-r-markdown

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!