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

时间:2017-03-09 09:04:14

标签: 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

2 个答案:

答案 0 :(得分:6)

Martin Schmelzers answer很棒,但我缺乏在脚注中格式化文本的可能性(即使文本斜体或粗体以正确格式化文献参考)。

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

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

enter image description here

---
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>

答案 1 :(得分:5)

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

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

---
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()),我们选择除标题幻灯片和后退幻灯片之外的所有幻灯片。对于每个人,我们添加一个脚注容器(<div class="footnotes"></div>)作为最后一个孩子。

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

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

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

结果如下:

enter image description here enter image description here

相关问题