【问题标题】:How to insert footnotes in ioslides presentations using RMarkdown如何使用 RMarkdown 在 ioslides 演示文稿中插入脚注
【发布时间】:2017-03-09 09:04:14
【问题描述】:

我使用 knitr 包创建了一个 ioslides 演示文稿,效果很好。现在我想在我的幻灯片上插入脚注。我没有在 SO 上找到任何有用的帖子。谁能告诉我如何在 R 幻灯片上添加脚注?有什么想法吗?

这是虚拟代码块:

---
title: "R presentation"
author: "me"
date: "March 9, 2017"
output: 
    ioslides_presentation
---

## slides one
 * content
 * introduction
## Content
- Bullet 1
- Bullet 2
- Bullet 3

【问题讨论】:

  • 您是指真正的脚注还是所有幻灯片都相同的页脚?
  • @MartinSchmelzer 不是真的,我只能在第一张或其他特定幻灯片上插入脚注。有什么想法吗?
  • pandoc 添加脚注的方式是 ^[footnote text] pandoc.org/MANUAL.html#footnotes ;但是,它不适用于ioslides,我不知道为什么,所以恐怕您需要在html中手动添加它们
  • @scoa 我可以用knitr 做到这一点吗? Rstudio 提醒我加载渲染 R 演示所需的所有包,pandoc 已安装。你介意用演示代码分享你的想法吗?
  • 是的,您可以,因为 knitr 使用 pandoc,但只能使用 ioslides 以外的输出格式...否则,您需要原始 html,也许应该用 标记您的问题以获得好的答案跨度>

标签: r knitr r-markdown ioslides


【解决方案1】:

Martin Schmelzers answer 很棒,但我无法在脚注中格式化文本(即,将文本设置为斜体或粗体以正确格式化文献参考)。

我更新了他的示例以允许这样做。请参阅下面的可重现示例。添加脚注如下:

<footnote>A *footnote* with **formatting**</footnote>

---
title: "New footnotes"
author: "Emil Tveden Bjerglund"
date: "August 8, 2017"
subtitle: "Inspired by Martin Schmelzer"
output: ioslides_presentation
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
<style>
div.footnotes {
  position: absolute;
  bottom: 0;
  margin-bottom: 10px;
  width: 80%;
  font-size: 0.6em;
}
</style>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
  $('slide:not(.backdrop):not(.title-slide)').append('<div class=\"footnotes\">');

  $('footnote').each(function(index) {
    var text  = $(this).html();
    var fnNum = (index+1).toString();
    $(this).html(fnNum.sup());

    var footnote   = fnNum + '. ' + text + '<br/>';
    var oldContent = $(this).parents('slide').children('div.footnotes').html();
    var newContent = oldContent + footnote;
    $(this).parents('slide').children('div.footnotes').html(newContent);
  });
});
</script>

## Testing footnotes
Some text.<footnote>And a footnote. http://stackoverflow.com</footnote>

Some more text.<footnote>And *another* **footnote**</footnote>

【讨论】:

  • 感谢您的贡献
【解决方案2】:

这是一种解决方法。它可能不是防弹的,需要进一步改进:


让我们从一个完全可重现的例子开始:

---
title: "Footnotes"
author: "Martin Schmelzer"
date: "9 3 2017"
output: ioslides_presentation
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

<style>
div.footnotes {
  position: absolute;
  bottom: 0;
  margin-bottom: 10px;
  width: 80%;
  font-size: 0.6em;
}
</style>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

<script>
  $(document).ready(function() {
    $('slide:not(.backdrop):not(.title-slide)').append('<div class=\"footnotes\">');

    $('footnote').each(function(index) {
      var text  = $(this).html();
      var fnNum = (index+1).toString().sup();
      $(this).html(text + fnNum);

      var footnote   = fnNum + ': ' + $(this).attr('content') + '<br/>';
      var oldContent = $(this).parents('slide').children('div.footnotes').html();
      var newContent = oldContent + footnote;
      $(this).parents('slide').children('div.footnotes').html(newContent);
    });
  });
</script>



## Try out some footnotes

Lets assume I have a footnote <footnote content="The first awesoem footnote!">here</footnote>. And here we are going to have another one: <footnote content="This is my second footnote!">#secFN</footnote>


## The Second Topic

See auto numbering for <footnote content = "The counter is not set back and continues on the next slide.">footnotes</footnote>

现在让我们看看我在这里做了什么:

1.我们为每张幻灯片底部的脚注容器添加了一些样式。

2.我们包含了 jQuery 库。

3.接下来是主脚本:

当文档完成加载 (document.ready()) 时,我们会选择除标题幻灯片和背景幻灯片之外的所有幻灯片。我们为它们中的每一个添加一个脚注容器 (&lt;div class="footnotes"&gt;&lt;/div&gt;) 作为最后一个子元素。

之后,我们只需浏览文档并搜索可以通过以下方式创建的脚注:

<footnote content="What should be written at the bottom?">Text</footnote>

我们选择所有脚注并对每个脚注应用一个函数,读取footnote 的内容并将其添加到容器中。脚注自动编号,上标添加sup()


结果如下:

【讨论】:

  • 这很棒。谢谢你,马丁。很高兴学习 Rmarkdown,干杯:)
  • 这只是解决了我的实现中的一个问题,即脚注四处滑动(而不是固定在幻灯片上)。谢谢你的贡献,马丁!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-05-17
  • 2019-04-03
  • 2021-01-30
  • 1970-01-01
  • 2014-11-05
  • 1970-01-01
  • 2014-09-01
相关资源
最近更新 更多