本文介绍了从 R markdown 输出的投影仪中的页码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的投影仪演示文稿中添加页码.我在Rmarkdown中使用以下代码(请参见下文).问题是页码被切断.我尝试使用几何来调整尺寸,但是我不断收到一条错误消息,指出它们不兼容.有人有什么想法吗?我已经花了数小时寻找解决方案.

  ---标题:我的标题作者:我"日期:"2016年5月5日"输出:beamer_presentation标头包括:-\ usepackage {fancyhdr}-\ pagestyle {fancy}-\ fancyhead {}-\ fancyfoot {}-\ fancyfoot [R] {\ thepage}-\ setbeamertemplate {footline} {\ thepage}---全局选项=======================================================```{r global_options,include = FALSE}#除非另有说明,否则请为标准图形输出设置工作区并排除组块代码,警告和消息:knitr :: opts_chunk $ set(fig.width = 6,fig.height = 4,fig.path ='Figs/',fig.show ='asis',include = FALSE,警告= FALSE,消息= FALSE)``````{r}图书馆(针织)``````{r汽车,include = TRUE,echo = FALSE}摘要(汽车)```#包括图```{r pressure,echo = FALSE,include = TRUE}情节(压力)``` 
解决方案

正如@Werner已经说过的那样,您不应该将 fancyhdr 与Beamer一起使用,因为Beamer有其自己的头部和脚线机制./p>

将页码添加到投影仪演示的最简单方法是使用预定义的模板之一,例如 \ setbeamertemplate {footline} [帧号] .不幸的是,似乎不可能在rmarkdown标头中包含可选参数,但是可以欺骗rmarkdown并将其隐藏在文件中:

  ---标题:我的标题作者:我"日期:"2016年5月5日"输出:beamer_presentation:keep_tex:是包括:in_header:preamble.tex---全局选项=======================================================```{r global_options,include = FALSE}#除非另有说明,否则请为标准图形输出设置工作区,并排除组块代码,警告和消息:knitr :: opts_chunk $ set(fig.width = 6,fig.height = 4,fig.path ='Figs/',fig.show ='asis',include = FALSE,警告= FALSE,消息= FALSE)``````{r}图书馆(针织)``````{r汽车,include = TRUE,echo = FALSE}摘要(汽车)```#包括图```{r pressure,echo = FALSE,include = TRUE}情节(压力)``` 

和preamble.tex

\setbeamertemplate{footline}[帧数] 

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)
```
解决方案

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]

这篇关于从 R markdown 输出的投影仪中的页码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 16:37