Pat*_*ick 7 label pandoc knitr r-markdown bookdown
我正在为需要补充材料的期刊写一篇文章。我希望使用一个独特的标签,SuppMat:而不是默认的标签fig:来将图表和表格发送到这个部分。
我知道使用乳胶的答案(在这里找到,在这里找到)但我必须在导出时完成这个docx(是的,我知道这很可怕,但合作者总是对的)
---
title: "My Title"
output:
bookdown::word_document2:
fig_caption: yes
link-citations: no
site: bookdown::bookdown_site
---
```{r setup, include=FALSE, cache=FALSE, echo=FALSE}
#create tables
table1 <- mtcars[1,2]
table2 <- mtcars[3,4]
#set knitr options
library(knitr)
knitr::opts_chunk$set(echo = FALSE,
warning = FALSE,
message = FALSE,
include = TRUE,
dpi = 300)
```
Table \@ref(tab:table1) and Figure \@ref(fig:figure1) ) should be displayed in ***Figure and Tables*** section
I need Supplementary Table \@ref(SuppMat:table2) and a Supplementary Figure \@ref(SuppMat:figure2) to be in Supplementary Material section. Here I try to refer to them using the label ***SuppMat:*** but the numbering is not shown in text.
# Supplementary Material {#SuppMat}
```{r table2}
knitr::kable(table2, caption= "This is the first table in Tables Section it should be in Supplementary Material")
```
```{r figure2, fig.cap="2nd Figure"}
knitr::include_graphics('https://www.rstudio.com/wp-content/uploads/2014/06/RStudio-Ball.png')
```
# Figure and Tables
```{r table1}
knitr::kable(table1, caption= "This is the first table in Tables Section")
```
```{r figure1, fig.cap="1st Figure"}
knitr::include_graphics('https://i.imgur.com/kFlO2Ev.png')
```
Run Code Online (Sandbox Code Playgroud)
这是输出的样子(错误以紫色突出显示)

在搜索多个论坛和几个小时后,我能够使用该包提出一个解决方案officedown。希望这可以帮助其他人。欲了解更多详细信息,请查看该run_autonum功能。
---
output: officedown::rdocx_document
---
```{r setup, include=FALSE}
pacman::p_load(officedown, officer, knitr)
knitr::opts_chunk$set(echo = FALSE, fig.cap = TRUE)
ft_base <- fp_text(font.family = "Cambria", font.size = 12, bold = TRUE)
ft1 <- update(ft_base, shading.color='#EFEFEF', color = "red")
ft2 <- update(ft_base, color = "#C32900")
srcfile <- file.path( R.home("doc"), "html", "logo.jpg" )
extimg <- external_img(src = srcfile, height = 1.06/5, width = 1.39/5)
```
## References
This is a reference to an supplementary image caption whose number is Supplementary Figure \@ref(fig:faithfuld-plot) and \@ref(fig:supp-bar).
Testing another figure with a barplot in Figure \@ref(fig:plotbar)
```{r fig.id="plotbar", fig.cap = "Main Figure"}
barplot(1:8, col=1:2)
```
## Supplementary Material
```{r fig.id="faithfuld-plot"}
knitr::include_graphics("images/MyImage.png") # Use your own figure here (I needed to test with knitr for my workflow)
block_caption("First Appendix Figure",
style = "Figure",
autonum = run_autonum(seq_id = 'fig',
bkm = 'faithfuld-plot',
pre_label = "Supplemental Figure ",
start_at=1))
```
```{r fig.id="supp-bar"}
barplot(1:8, col=1:2)
block_caption("Second Appendix Figure",
style = "Figure",
autonum = run_autonum(seq_id = 'fig',
bkm = 'supp-bar',
pre_label = "Supplemental Figure ",
start_at= NULL))
```
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
419 次 |
| 最近记录: |