首页 > 解决方案 > 将 Rmd 中的目录和从属关系列表分离为 PDF 文件

问题描述

最近有人批评我在从 R Markdown 文件创建 PDF 时没有明确区分 TOC 和 Affiliation 列表。

我的 YAML 就是这个

---
title: "title"
author:
  - Name author 1:
      email: paleomariomm@gmail.com
      institute: [cenieh, ucl1, ppex]
      correspondence: true
  - Name author 2:
      institute: [ubu]
institute:
  - cenieh: Centro Nacional de Investigación sobre la Evolución Humana (CENIEH), Paseo Sierra de Atapuerca 3, 09002, Burgos, Spain
  - ucl1: Department of Anthropology, University College London, London, WC1H 0BW, UK
  - ppex: Equipo Primeros Pobladores de Extremadura, Casa de Cultura Rodríguez Moñino, Cáceres, Spain
  - ubu: Laboratorio de Evolución Humana, Universidad de Burgos, Edificio I+D+i, Burgos, Spain
output: 
  pdf_document: 
    number_sections: yes
    pandoc_args:
      - '--lua-filter=lua/scholarly-metadata.lua'
      - '--lua-filter=lua/author-info-blocks.lua'
    toc: yes
    toc_depth: 4
---

通过将此 Rmd 文件转换为 PDF,我看到:

在此处输入图像描述

如您所见,TOC 和从属关系列表之间可能会出现一些潜在的误解,因为从属关系列表就在目录的下方。

我想清楚地分开它们。我想到了不同的可能性:

我一直在解决这些情况,但没有成功。关于如何实施其中任何一个的任何想法?

标签: markdownr-markdownknitrpandoctableofcontents

解决方案


隶属关系列表作为主体的一部分添加。Pandoc 将目录作为正文的第一项插入,这就是从属关系出现在 TOC 之后的原因。最好的解决方法是禁用自动 TOC 插入,并手动调用 LaTeX 命令。

output: 
  pdf_document: 
    number_sections: yes
    pandoc_args:
      - '--lua-filter=lua/scholarly-metadata.lua'
      - '--lua-filter=lua/author-info-blocks.lua'
    toc: no

然后加

```{=latex}
\setcounter{tocdepth}{4}
\tableofcontents
```

在文档的顶部。Lua 过滤器会将 affiliations 部分推到顶部,在目录上方,pandoc 不会更改顺序。


推荐阅读