RMarkdown for Word 文档中的交叉引用 [英] Cross-references in RMarkdown for Word documents

查看:49
本文介绍了RMarkdown for Word 文档中的交叉引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 Rmd 文件,该文件将被编入 Word 中的报告中.我正在尝试为图形创建一个标签,并对其进行交叉引用,如下所示:

I am writing an Rmd file that will be knitted to a report in Word. I am trying to create a label for a figure, and a cross reference to it, as in:

如图\ref{fig:TotalCarStock}等,等等

```{r TotalCarStock, echo=FALSE, fig.cap="Forecasted versus actual car stock", out.width = '100%'}
knitr::include_graphics("C:/Usr/WP vehicle stock/TotalCarStock.jpg")
```

我在这里看到的所有讨论都表明这在创建 pdf 文档时可以正常工作,但我希望将我的 Rmd 文件编织"到 Word 文档中.Word 文档创建正确,除了标签和交叉引用保持空白.

All discussions I have seen here indicate that this works correctly when creating a pdf document, but I wish to "knit" my Rmd file to a Word document. The Word document is created correctly, except that the label and the cross reference remain blank.

推荐答案

@LaurentFrankx 最后,我找到了解决方案:如果你使用 bookdown::word_document2: 在 YAML 标头的 output 行中代替 word_document,如下所示.

@LaurentFrankx Finally, I found the solution: you will be able to get the following result, if you use bookdown::word_document2: instead of word_document in the output line of YAML header, as shown below.

---
title: "VHS Report"
author: "Laurent Franckx"
date: "14 September 2018"
output: 
  bookdown::word_document2:
  fig_caption: yes
#pdf_document: default
---

As illustrated in Figure \@ref(fig:TotalCarStock), etc, etc. However, `out.width = '100%'` in an R chunk cannnot be specified when we want to produce a `.docx` output, because `out.width = '100%'` is used for creating `.pdf` outcome.

```{r TotalCarStock, echo=FALSE, fig.cap="Forecasted versus actual car stock"}
knitr::include_graphics("https://i.stack.imgur.com/JlNbf.png")
```

bookdown::word_document2:***_document2 函数由@Yihui 创建.我们可以在官方指南中看到它们的用法.这些使我们能够放置自动编号,如此处中所述一>.

bookdown::word_document2: and other ***_document2 functions are created by @Yihui. We can see their usage in the official guidebook. These enable us to put the automatic numbering, as described in here.

如需进一步定制,我们可以参考与Rmd合作愉快以docxem>.虽然文章介绍了如何使用word_document来配置格式,但这些提示在更新后的函数word_document2中仍然有效和有用.

For farther customization, we can consult the article titled Happy collaboration with Rmd to docx. Although the article introduces how to configure the formatting with word_document, the tips are still valid and useful with the updated function, word_document2.

这篇关于RMarkdown for Word 文档中的交叉引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆