如何从RMarkdown文档中正确为Word中的标题编号 [英] How to properly number headings in Word from a RMarkdown document
问题描述
我正在创建一个RMarkdown文档,我想使用RStudio在MS Word中导出该文档.
我想要一个目录和标题列表.这是我的降价示例文件:
---
title: "Test"
author: "Ben"
date: "`r format(Sys.time(), '%d/%m/%Y')`"
output:
word_document:
toc: yes
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# Header 1
## Header 2
## Header 2
### Header 3
这将产生以下单词doc:
这是一个好的开始.遵循本教程之后,我在Word中编辑了输出文档的标题样式以使其编号. /p>
我还更改了目录标题标题,使其基于普通文本而不是另一个标题,否则目录标题也将进行编号.
我将修改后的文档保存在模板文件夹中,并将其添加为markdown标头中的引用:
---
title: "Test"
author: "Ben"
date: "`r format(Sys.time(), '%d/%m/%Y')`"
output:
word_document:
toc: yes
reference_docx: "../templates/word-styles-reference-01.docx"
---
以下是输出:
现在,我想在目录后进行分页,所以我遵循了 这是输出: 我现在有分页符,但标题6标题由Word编号,因此我的第一个标题编号为2. 最后,它是:
Frost_Maggot在评论中建议,
也许尝试在与R共享的Word中修改其他样式 降价.如果您没有在R降价中使用块引号,则此 可能与MS Word样式中的报价有关?
这确实对我有用,因为我没有在文档中使用quote
样式.
I'm creating a RMarkdown document that I want to export in MS Word with RStudio.
I want a table of contents and numbered headings. Here is my sample markdown document:
---
title: "Test"
author: "Ben"
date: "`r format(Sys.time(), '%d/%m/%Y')`"
output:
word_document:
toc: yes
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# Header 1
## Header 2
## Header 2
### Header 3
This produces the following word doc:
That's a good start. Following this tutorial, I edited the heading styles of the output document in Word to make them numbered.
I also changed the Table of contents title heading so that it's based on normal text and not another heading, otherwise the table of contents title gets numbered as well.
I saved the modified document in a template folder and added it as reference in the markdown header:
---
title: "Test"
author: "Ben"
date: "`r format(Sys.time(), '%d/%m/%Y')`"
output:
word_document:
toc: yes
reference_docx: "../templates/word-styles-reference-01.docx"
---
Here is the output:
Now, I want a page break after my table of contents, so I followed this other tutorial and changed my Heading 6 so that it is white, very small, based on the normal style and adds a page break afterwards.
The new markdown file looks like this:
---
title: "Test"
author: "Ben"
date: "`r format(Sys.time(), '%d/%m/%Y')`"
output:
word_document:
toc: yes
reference_docx: "../templates/word-styles-reference-01.docx"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
###### Page break after table of contents
# Header 1
## Header 2
## Header 2
### Header 3
And here is the output:
I now have my page break but the Heading 6 title is numbered by Word and thus my first title is numbered 2.
In the end, it's either:
- a word question: how do I modify the style of Heading 6 so it's not numbered?
- an R question: how can I add a page break without using word headings?
As suggested by Frost_Maggot in the comments,
Maybe try modifying a different style in Word that is shared with R Markdown. If you are not using block quotes in your R markdown this might relate to quote in the MS Word stylings?
This indeed works for me as I don't use the quote
style in my document.
这篇关于如何从RMarkdown文档中正确为Word中的标题编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!