r - 在 RMarkdown PDF 中,将节编号从“X Section”更改为“Section X”
问题描述
我正在使用 RMarkdown 做课程笔记,每个主要部分都对应一个给定的讲座。我想让章节标题自动格式化为“第 1 讲”、“第 2 讲”等。这基本上就是我要找的。
第1讲
翻过课程表。
第2讲
实际学习一些东西
但是,当我使用 RMarkdown 的默认设置时,我得到以下格式(名称前面带有节号):
1场讲座
翻过课程表。
2 讲座
确实学到了一些东西。
如何获得自动编号:
(1) 跟随名字(如“October 1st - Lecture 1 ”)
或者
(2) 在名称中被引用(例如使用某种伪代码“ October 1st - Lecture {%section_number%}
”)?
下面是 RMarkdown 代码的最小可重现示例,可以将其编织为 PDF。
---
title: "Course_Notes"
output:
pdf_document:
number_sections: true
---
# Lecture
Going over the syllabus.
# Lecture
Actually learning some stuff
解决方案
根据关于更改部分标题格式的 TeX 答案,您可以使用titlesec TeX 包更改部分格式,如下所示:
\usepackage[explicit]{titlesec}
\titleformat{\section}{\normalfont\Large\bfseries}{}{0em}{#1\ \thesection}
但是,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
推荐阅读
- angular - 在选项卡之间共享 http 请求调用
- dask - 工人无法用 rasterio 反序列化
- inform7 - 如何访问玩家刚刚输入的动词?
- javascript - 在 Expo 项目中从 TextInput 获取文本时未定义不是对象
- java - 具有自动文本定位功能的 Graphic2D 生成图像
- ruby-on-rails - 如何使用 ruby 在两个新行上拆分文本
- python - 页面刷新时取消POST
- python-3.x - 是否可以使用 python pptx 删除形状的线条?
- laravel - 你如何在 Laravel (MPA) 中路由 Vue 布局
- python-3.x - MST 挑战给出“超时”错误