3

I've been recently criticized of not clearly separating TOC and Affiliation list when creating a PDF from a R Markdown file.

My YAML is this one

---
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
---

By converting this Rmd file to PDF, I see this:

enter image description here

As you can identify, some potential misundertanding might appear between the TOC and Affiliation list, as the affiliation list is just below the table of contents.

I would like to separate them clearly. I thought different possibilities:

  • Introducing a line that separates both sections.
  • Adding a small title at the top of the affiliation list saying Affiliation.
  • Reversing the order and placing the affiliation list just below the authors.

I have been working around with these situations but unsuccessfully. Any idea on how to implement any of those?

antecessor
  • 2,688
  • 6
  • 29
  • 61
  • Where do these lua filters come from? They are unknown on my system. – Ralf Stubner Sep 19 '19 at 08:50
  • Both come from GitHub: https://github.com/pandoc/lua-filters/blob/master/scholarly-metadata/scholarly-metadata.lua and https://github.com/pandoc/lua-filters/blob/master/author-info-blocks/author-info-blocks.lua – antecessor Sep 19 '19 at 09:28
  • With these lua filters installed I get the error `[string "lua/author-info-blocks.lua"]:168: attempt to call a nil value (method 'map')` with pandoc version 2.3.1. BTW, have you looked at the formats provided by packages like `rticles` or `pinp`? – Ralf Stubner Sep 19 '19 at 09:38
  • have you saved them in a lua folder? – antecessor Sep 19 '19 at 09:41
  • Yes, otherwise I would have got a "file not found" error. – Ralf Stubner Sep 19 '19 at 09:42
  • I don't get any error when converting it to PDF... – antecessor Sep 19 '19 at 10:46
  • 1
    @RalfStubner that's likely caused by an older pandoc version. See [this GitHub issue](https://github.com/pandoc/lua-filters/issues/64). – tarleb Sep 20 '19 at 08:42

3 Answers3

3

The affiliation list is added as part of the main body. Pandoc inserts the table of contents as the first item of the body, which is why the affiliations appear after the TOC. The best work-around is to disable automatic TOC insertion, and to call the LaTeX command manually.

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

Then add

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

at the top of your document. The Lua filters will push the affiliations section to the top, above the table of contents, and pandoc won't change the order.

tarleb
  • 19,863
  • 4
  • 51
  • 80
1

As you note one solution would be to add some space after the TOC. You can do this by adding

header-includes:
    - \usepackage{xpatch}
    - \xapptocmd{\tableofcontents}{\vspace{2em}}{}{}

to your YAML header.

Ralf Stubner
  • 26,263
  • 3
  • 40
  • 75
0

expanding a little bit on @tarleb's answer:

To place the toc wherever needed without messing with tex files,

Turn off automatic toc insertion first in the YAML metadata (no need here to use lua filters).

---
title: "myTitle"
date: "`r Sys.Date()`"
output: 
  pdf_document:
    toc: no
    number_sections: true
urlcolor: blue
editor_options:
  chunk_output_type: console
documentclass: report
---

Then, wherever you want the toc to be in your document, add

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

You can then place this toc anywhere using latex macros such as \newpage or \hfill\break for example.

---
title: "myTitle"
date: "`r Sys.Date()`"
output: 
  pdf_document:
    toc: no
    number_sections: true
urlcolor: blue
editor_options:
  chunk_output_type: console
---
\newpage
```{=latex}
\setcounter{tocdepth}{4}
\tableofcontents
```
\newpage

Note: documentclass: report in the metadata will automatically separate the toc from the title, but won't allow to separate it from the remainder of the document.

separated

gaut
  • 5,771
  • 1
  • 14
  • 45