问题
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