2

I want to knit a pdf-document but the keywords don't appear in the final document. Can someone say me what I'm doing wrong?

---
title: "title"
subtitle: "subtitle"
author: "author"
date: "09 04 2019"
output:
  pdf_document:
keywords: "word1, word2, word3"
footerdate: yes
abstract: 'Insert abstract here'
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

# Introduction

enter image description here

TobKel
  • 1,293
  • 8
  • 20
  • Try `keywords: ["word1", "word2, "word3"]` – TheRimalaya Apr 09 '19 at 10:05
  • No. It does not work. – TobKel Apr 09 '19 at 10:07
  • Possible duplicate of [knitr/pandoc: article template supporting keywords: and linespacing:](https://stackoverflow.com/questions/37978637/knitr-pandoc-article-template-supporting-keywords-and-linespacing) – A. Stam Apr 09 '19 at 10:07
  • Yes, the problem is that the default template `rmarkdown` provide in https://github.com/rstudio/rmarkdown/blob/master/inst/rmd/latex/default.tex does not contain `keyword`. You can always use a custom template by copying the one in github and customize it can be the easiest way. – TheRimalaya Apr 09 '19 at 10:15
  • Is there no way to change my code, that I can add the keywords in the header? – TobKel Apr 09 '19 at 10:25
  • As specified in my linked question, you can create a custom template but there is no way to simply change the R code to get the desired result. – A. Stam Apr 09 '19 at 11:09
  • Okay. Thank you. – TobKel Apr 09 '19 at 11:16
  • you can add a line to an existing header element to approximate the result you're looking for, keeping in mind the line will inherit the style of whatever element you choose to extend. `date: | | "09 04 2019" | "keywords: word1, word2, word3"` – Raoul Duke Apr 09 '19 at 14:37

2 Answers2

0

When knitting to PDF, keywords are sent to the file metadata but are not actually visible in the file. Source

A. Stam
  • 2,148
  • 14
  • 29
0

You can customize the template for PDF generation or render Rmd files with base_format: rticles::elsevier_article. However, there is another way to show keywords on the PDF just by adding few codes to the Rmd file:

  1. Add a LaTeX code to provide the \keyword command (\providecommand{\keywords}[1]{\textbf{\textit{Keywords---}} #1}) into YAML's header-includes key;
  2. Add keywords in the text section using the LaTeX command
---
title: "title"
subtitle: "subtitle"
author: "author"
date: "09 04 2019"
output:
  pdf_document:
# keywords: "word1, word2, word3" # <- You don't have to add your keywords here since they only appear as the 'invisible' metadata of PDF
footerdate: yes
abstract: 'Insert abstract here'
header-includes:
  - |
    ```{=latex}
    \providecommand{\keywords}[1]{\textbf{\textit{Keywords---}} #1}
    ```
---

```{=latex}
\keywords{word1, word2, word3}
```

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

# Introduction
Carlos Luis Rivera
  • 3,108
  • 18
  • 45