在 Rmarkdown 中的参考书目后添加图形和表格
Adding figures and tables after bibliography in Rmarkdown
我想在 R Markdown 文档的参考书目之后添加表格和图形。然而,R Markdown 文档默认总是将参考书目添加到报告的末尾。
有没有一种简单的方法可以在引用后向文档添加内容?
尝试过的解决方案
A previous answer 表明有一种方法可以将附录放在 R Markdown 中的参考书目之后。此附录是一个单独的文件,并在 YAML header 中以 after_body
添加到文档中。我尝试了 2 种不同的可能解决方案,其中 none 有效。
- 我试图将我的附录放在不同的文件中,但我 运行 遇到了在主文件中丢失我的引用的问题,因为所有附录都在 cross-referenced [=43] =] 的论文。一旦我将它们放在不同的文件中,所有引用都会变成 ??。
- 我将所有图形和表格放在不同的文件中,同时也将它们保存在主文件中。然后,我使用
results = "hide"
将它们隐藏在主文件中。这个想法是创建 2 个单独的 PDF 并将它们合并。不幸的是,当数字被隐藏时,引用也会变成 ??。
附加信息
- 我正在使用输出格式
bookdown:pdf_document2
- 我的图形是由
.R
文件创建的,并使用 include_graphics()
. 导入到我的 R Markdown 文件中
与其尝试将内容包含在 after_body 中,不如重新定位参考书目在文档中出现的位置。如 this answer 中所述,您可以使用 <div id="refs"></div>
选择参考书目出现的位置。
其次,您可以使用 bookdown 轻松地在文档中添加附录。使用 header # (APPENDIX) Appendix {-}
会将后面的所有节号从数字更改为字母。查看 bookdown book
在完整示例中使用:
---
title: "Untitled"
output: bookdown::pdf_document2
references:
- id: fenner2012a
title: One-click science marketing
author:
- family: Fenner
given: Martin
container-title: Nature Materials
volume: 11
URL: 'http://dx.doi.org/10.1038/nmat3283'
DOI: 10.1038/nmat3283
issue: 4
publisher: Nature Publishing Group
page: 261-263
type: article-journal
issued:
year: 2012
month: 3
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(magrittr)
```
# Introduction
Here is a citation [@fenner2012a]
# References {-}
<div id="refs"></div>
\newpage
# (APPENDIX) Appendix {-}
# Appendix A
Here is your table
```{r table, fig.pos="H"}
knitr::kable(mtcars[1:5, 1:5], caption = "A table") %>%
kableExtra::kable_styling(latex_options = "HOLD_position")
```
Note: this will only work if you use pandoc's built-in citation package and won't work if you set citation_package: natbib
in the YAML
我想在 R Markdown 文档的参考书目之后添加表格和图形。然而,R Markdown 文档默认总是将参考书目添加到报告的末尾。
有没有一种简单的方法可以在引用后向文档添加内容?
尝试过的解决方案
A previous answer 表明有一种方法可以将附录放在 R Markdown 中的参考书目之后。此附录是一个单独的文件,并在 YAML header 中以 after_body
添加到文档中。我尝试了 2 种不同的可能解决方案,其中 none 有效。
- 我试图将我的附录放在不同的文件中,但我 运行 遇到了在主文件中丢失我的引用的问题,因为所有附录都在 cross-referenced [=43] =] 的论文。一旦我将它们放在不同的文件中,所有引用都会变成 ??。
- 我将所有图形和表格放在不同的文件中,同时也将它们保存在主文件中。然后,我使用
results = "hide"
将它们隐藏在主文件中。这个想法是创建 2 个单独的 PDF 并将它们合并。不幸的是,当数字被隐藏时,引用也会变成 ??。
附加信息
- 我正在使用输出格式
bookdown:pdf_document2
- 我的图形是由
.R
文件创建的,并使用include_graphics()
. 导入到我的 R Markdown 文件中
与其尝试将内容包含在 after_body 中,不如重新定位参考书目在文档中出现的位置。如 this answer 中所述,您可以使用 <div id="refs"></div>
选择参考书目出现的位置。
其次,您可以使用 bookdown 轻松地在文档中添加附录。使用 header # (APPENDIX) Appendix {-}
会将后面的所有节号从数字更改为字母。查看 bookdown book
在完整示例中使用:
---
title: "Untitled"
output: bookdown::pdf_document2
references:
- id: fenner2012a
title: One-click science marketing
author:
- family: Fenner
given: Martin
container-title: Nature Materials
volume: 11
URL: 'http://dx.doi.org/10.1038/nmat3283'
DOI: 10.1038/nmat3283
issue: 4
publisher: Nature Publishing Group
page: 261-263
type: article-journal
issued:
year: 2012
month: 3
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(magrittr)
```
# Introduction
Here is a citation [@fenner2012a]
# References {-}
<div id="refs"></div>
\newpage
# (APPENDIX) Appendix {-}
# Appendix A
Here is your table
```{r table, fig.pos="H"}
knitr::kable(mtcars[1:5, 1:5], caption = "A table") %>%
kableExtra::kable_styling(latex_options = "HOLD_position")
```
Note: this will only work if you use pandoc's built-in citation package and won't work if you set
citation_package: natbib
in the YAML