Search code examples
latexr-markdown

fontsize and enumitem failed in rmarkdown pdf


My little rmarkdown example is as follows:

---
# documentclass: article
output: 
  pdf_document: 
    latex_engine: xelatex
# linestretch: 1.5
fontsize: 18pt # 10pt
header-includes:
  - \usepackage{lipsum} 
  - \usepackage{setspace}\doublespacing #\singlespacing 
  - \usepackage[shortlabels]{enumitem}
  - \setlist{nosep}
  - \setlist{noitemsep}
  - \setcounter{enumi}{-1}
---

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

## random

\lipsum

## R Markdown

itemize itemize itemize itemize itemize itemize itemize itemize itemize 

- aaa
- bbb
- ccc

enumerate enumerate enumerate enumerate enumerate enumerate enumerate enumerate enumerate 

1. uuu
1. vvv
1. www

why why why why why why why why why why why why why why why why why why why why why 

I have two issues: changing fontsize from 10pt to 18pt is not working; commenting \setlist{nosep}, \setlist{noitemsep} and \setcounter{enumi}{-1} or not makes no difference. Why these happen since this example is quite simple? (ps: setspace works well)


Solution

  • 18pt is not an allowed class option. With the default article class only a handful of normal sizes are defined. You can extent this by switching to the extarticle class which has the 17pt option:

    ---
    documentclass: extarticle
    output: 
      pdf_document: 
        latex_engine: xelatex
    # linestretch: 1.5
    fontsize: 17pt # 10pt
    header-includes:
      - \usepackage{lipsum} 
      - \usepackage{setspace}\doublespacing #\singlespacing 
      - \usepackage[shortlabels]{enumitem}
      - \setlist{nosep}
      - \setlist{noitemsep}
    ---
    
    ```{r setup, include=FALSE}
    knitr::opts_chunk$set(echo = TRUE)
    ```
    
    ## random
    
    \lipsum
    
    ## R Markdown
    
    itemize itemize itemize itemize itemize itemize itemize itemize itemize 
    
    - aaa
    - bbb
    - ccc
    
    enumerate enumerate enumerate enumerate enumerate enumerate enumerate enumerate enumerate 
    
    1. uuu
    1. vvv
    1. www
    
    why why why why why why why why why why why why why why why why why why why why why