如何从 RMarkdown 文档中正确编号 Word 中的标题 [英] How to properly number headings in Word from a RMarkdown document

查看:34
本文介绍了如何从 RMarkdown 文档中正确编号 Word 中的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 RMarkdown 文档,我想使用 RStudio 在 MS Word 中导出该文档.

我想要一个目录和编号的标题.这是我的示例降价文档:

---书名:《测试》作者:本"日期:`r 格式(Sys.time(),'%d/%m/%Y')`"输出:word_document:托克:是的---```{r 设置,包括 = FALSE}knitr::opts_chunk$set(echo = TRUE)``# 标题 1## 标题 2## 标题 2### 标题 3

这会产生以下单词 doc:

这是一个好的开始.按照

现在,我想在我的目录之后分页,所以我遵循了

我现在有了分页符,但标题 6 的标题按 Word 编号,因此我的第一个标题编号为 2.

最后,要么:

  • 一个单词问题:如何修改标题 6 的样式,使其没有编号?
  • 一个 R 问题:如何在不使用词标题的情况下添加分页符?

解决方案

正如 Frost_Maggot 在评论中所建议的,

<块引用>

也许尝试在 Word 中修改与 R 共享的不同样式降价.如果您没有在 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屋!

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