1

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 是 的url索引mylastslide(我+ 1slideNumberFormat函数中使用,因为索引从 0 开始。)

谢谢。

4

1 回答 1

2

您当然可以将最后一张幻灯片的格式设置为固定值,例如%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

在幻灯片底部---标记后。所以这里有一个完整的例子,基于xaringan模板的前几张幻灯片:

---
title: "Presentation Ninja"
subtitle: "⚔&lt;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 of 4”到“5 of 4”。

编辑添加:正如评论中所讨论的,这不能正确处理增量幻灯片: 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>
于 2020-12-04T17:54:18.210 回答