如何使用RMarkdown在ioslides演示文稿中插入脚注

7 r knitr r-markdown ioslides

我使用该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
Run Code Online (Sandbox Code Playgroud)

Mar*_*zer 6

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


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

---
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>
Run Code Online (Sandbox Code Playgroud)

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

1.我们在每张幻灯片的底部,我们的注脚容器中添加一些风格.

2.我们包含了jQuery库.

3.接下来是主要的脚本:

当文档完成加载(document.ready())后,我们选择除标题幻灯片和后退幻灯片之外的所有幻灯片.对于每个人,我们添加一个脚注容器(<div class="footnotes"></div>)作为最后一个孩子.

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

<footnote content="What should be written at the bottom?">Text</footnote>
Run Code Online (Sandbox Code Playgroud)

我们选择所有脚注并为每个脚注应用一个函数,该函数读出内容footnote并将其添加到容器中.脚注获得自动编号,并添加上标sup().


这就是结果:

在此输入图像描述 在此输入图像描述


emi*_*ltb 6

Martin Schmelzers的回答非常好,但我缺乏在脚注中格式化文本的可能性(即使文本斜体或粗体以正确格式化文献参考).

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

<footnote>A *footnote* with **formatting**</footnote>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

---
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>
Run Code Online (Sandbox Code Playgroud)