在RMarkdown PDF中,将部分编号从“ X部分”更改为“ X部分”

bsc*_*idr 3 latex r knitr r-markdown

我正在使用RMarkdown做课程笔记,每个主要部分都对应于一个给定的讲座。我想将节标题自动设置为“第1课”,“第2课”等格式。这基本上是我要寻找的内容。

讲座1

复习课程。

第二讲

实际学习一些东西

但是,当我使用RMarkdown的默认设置时,会得到以下格式(节号在名称前):

1讲

复习课程。

2讲座

实际学习一些东西。

我如何将自动编号设置为:

(1)跟随名称(例如“ 10月1日-讲座1 ”)

要么

(2)是否以名称引用(例如,使用某种伪代码“ October 1st - Lecture {%section_number%}”)?

下面是可复制为PDF的RMarkdown代码的最小可复制示例。

---
title: "Course_Notes"
output: 
  pdf_document:
    number_sections: true
---

# Lecture
Going over the syllabus.

# Lecture
Actually learning some stuff
Run Code Online (Sandbox Code Playgroud)

Mik*_*ila 7

根据有关更改部分标题格式的TeX答案,您可以使用titlesec TeX软件包来更改部分格式,如下所示:

\usepackage[explicit]{titlesec}
\titleformat{\section}{\normalfont\Large\bfseries}{}{0em}{#1\ \thesection}
Run Code Online (Sandbox Code Playgroud)

但是,titlesec在Pandoc中无法立即使用:另一个问答显示您需要添加subparagraph: yes到YAML标头中才能使其正常工作。

将它们放在一起,进行以下修改可以使您获得想要的结果:

---
title: "Course_Notes"
output: 
  pdf_document:
    number_sections: true
header-includes:
  - \usepackage[explicit]{titlesec}
  - \titleformat{\section}{\normalfont\Large\bfseries}{}{0em}{#1\ \thesection}
subparagraph: yes
---

# Lecture
Going over the syllabus.

# Lecture
Actually learning some stuff
Run Code Online (Sandbox Code Playgroud)