在xaringan
演示中,slideNumberFormat
参数通常设置为%current% / %total%
。是否可以在此参数中使用特定的幻灯片编号?
例如,如果我有一个";最后的";幻灯片如下:
---
name: mylastslide
# Thanks
后面有附录幻灯片,我想显示像%current% / %mylastslide%
这样的幻灯片编号,%mylastslide%
是我的幻灯片编号mylastslide
。
谢谢。
[根据@user2554330建议编辑]
对于此代码,使用增量幻灯片
---
title: "Presentation Ninja"
subtitle: "⚔<br/>with xaringan"
author: "Yihui Xie"
institute: "RStudio, PBC"
date: "2016/12/12 (updated: `r Sys.Date()`)"
output:
xaringan::moon_reader:
lib_dir: libs
---
background-image: url(https://upload.wikimedia.org/wikipedia/commons/b/be/Sharingan_triple.svg)
```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)
```
<script>
var slideshow = remark.create({slideNumberFormat : function (current, total) {
return 'Slide ' + current + ' of ' + (this.getSlideByName("mylastslide").getSlideIndex() + 1); },
highlightStyle: "github",
highlightLines: true,
countIncrementalSlides: false});
</script>
Image credit: [Wikimedia Commons](https://commons.wikimedia.org/wiki/File:Sharingan_triple.svg)
---
class: center, middle
# xaringan
---
hello
--
world
--
thanks
--
really
--
byebye
---
name: mylastslide
# Final slide
Install the **xaringan** package from [Github](https://github.com/yihui/xaringan):
```{r eval=FALSE, tidy=FALSE}
devtools::install_github("yihui/xaringan")
```
---
# Appendix
最后一张幻灯片(即附录(编号为Slide 6 of 9
(而不是Slide 6 of 5
(,9是mylastslide
的url索引。(我在slideNumberFormat
函数中使用了+ 1
,因为索引从0开始。(
谢谢。
您当然可以将最后一张幻灯片的格式设置为固定值,例如%current% / 34
。但您也可以将其设置为Javascript函数。(编辑后添加:(棘手的部分是,您还需要包括通常会出现在nature
参数中的所有选项。所以你想要像这样的东西
<script>
var slideshow = remark.create({slideNumberFormat : function (current, total) {
return 'Slide ' + current + ' of ' + this.getSlideByName("mylastslide").getSlideIndex(); },
highlightStyle: "github",
highlightLines: true,
countIncrementalSlides: false});
</script>
您通过将文本命名幻灯片
name: mylastslide
在CCD_ 14标记之后的幻灯片底部。这里有一个完整的例子,基于xaringan
模板的前几张幻灯片:
---
title: "Presentation Ninja"
subtitle: "⚔<br/>with xaringan"
author: "Yihui Xie"
institute: "RStudio, PBC"
date: "2016/12/12 (updated: `r Sys.Date()`)"
output:
xaringan::moon_reader:
lib_dir: libs
---
background-image: url(https://upload.wikimedia.org/wikipedia/commons/b/be/Sharingan_triple.svg)
```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)
```
<script>
var slideshow = remark.create({slideNumberFormat : function (current, total) {
return 'Slide ' + current + ' of ' + this.getSlideByName("mylastslide").getSlideIndex(); },
highlightStyle: "github",
highlightLines: true,
countIncrementalSlides: false});
</script>
???
Image credit: [Wikimedia Commons](https://commons.wikimedia.org/wiki/File:Sharingan_triple.svg)
---
class: center, middle
# xaringan
### /ʃaː.'riŋ.ɡan/
---
class: inverse, center, middle
# Get Started
---
name: mylastslide
# Hello World
Install the **xaringan** package from [Github](https://github.com/yihui/xaringan):
```{r eval=FALSE, tidy=FALSE}
devtools::install_github("yihui/xaringan")
```
这有5张幻灯片;第1页,共4页";至";4〃中的5〃;。
编辑添加:正如评论中所讨论的,这不能正确处理增量幻灯片:getSlideIndex()
单独计算增量幻灯片。我们希望使用getSlideNumber()
,当我们使用选项countIncrementalSlides: false
时,它在所有这些选项上保持不变。但是,在线版本的remark-latest.min.js
中没有getSlideNumber()
,您需要索取remark-0.15.0.min.js
。
您可以使用以下YAML:来完成此操作
xaringan::moon_reader:
lib_dir: libs
chakra: https://remarkjs.com/downloads/remark-0.15.0.min.js
在此之后,下面的代码运行良好:
<script>
var slideshow = remark.create({slideNumberFormat : function (current, total) {
return 'Slide ' + current + ' of ' + this.getSlideByName("mylastslide").getSlideNumber(); },
highlightStyle: "github",
highlightLines: true,
countIncrementalSlides: false});
</script>