我想用{officedown}.docx
创建一个报告,但不是使用“书签”引用类型来交叉引用用户文档ch.4.6和ch.4.7中建议的表格和图形,我希望我的引用是结果中的实际“Figure”和“Table”引用类型。正如在此 stackoverflow 帖子中所讨论的,这将需要和word 字段,并且答案显示了如何通过or来实现此功能。.docx
{SEQ Figure \\* arabic}
{SEQ Table \\* arabic}
officer::slip_in_seqfield()
crosstable::body_add_table_legend()
但是,我认为,这些获取实际“Figure”和“Table”引用类型的方法仅适用于 {officer} 语法,而不适用于 {officedown} 语法。说清楚,到目前为止我明白了
- {officer} 语法作为 R 脚本,使用以[示例]
dplyr
开头的链read_docx() %>%
- {officedown} 语法作为 Rmd 脚本,在块内使用
block_caption()
和使用run_autonum()
[示例]
(如果我错了请纠正我)
因此,我想知道是否有办法修改 {officedown} 中建议的方法,以获得实际的“图形”和“表格”引用类型,我也可以在文本中交叉引用。以下是使用标准建议方法的示例:
You can also make use of the `run_autonum()` and `block_caption()` functions
of the {officer} package. Here are the cross references to Table \@ref(tab:tabmtcars2)
and Figure \@ref(fig:figmtcars2). This approach can be used for tables and figures
and the corresponding reference type in MS Word will always be "bookmark".
```{r}
# Table
run_autonum(seq_id = "tab",
bkm = "tabmtcars2") %>%
block_caption(autonum = .,
label = "mtcars table",
style = "Table Caption")
head(mtcars)
# Figure
ggplot(head(mtcars), aes(x = mpg, y = hp)) +
geom_point() + theme_bw()
run_autonum(seq_id = "fig",
bkm = "figmtcars2") %>%
block_caption(autonum = .,
label = "mtcars figure",
style = "Image Caption")
```