Remove chapter headings in Rmarkdown for PDF reports - pdf

I am aware that there are already an infinite number of entries here about the YAML header in rmarkdown. However, I have not yet been able to find an answer to the following question:
I need:
a PDF
a title page
the table of contents starting on the second page
a page numbering starting at the table of contents
numbered sections
no automatic chapter numbering
I would like to do this without LateX code, bookdown or the import of any text files.
Except for the last point, this seems to work with documentclass: report. Unfortunately I can't get rid of the chapters. Is there no pure rmarkdown YAML header solution for this?
---
title: The Force
subtitle: May it be with you
author: "Obi-Wan Kenobi"
date: "`r Sys.Date()`"
output:
pdf_document:
toc: yes
toc_depth: 3
number_sections: true
documentclass: report
---
# Introduction
## Sub
### SubSub
# Methods
## Sub
### SubSub

We can use this answer from Tex-StackExchange to do this.
---
title: The Force
subtitle: May it be with you
author: "Obi-Wan Kenobi"
date: "`r Sys.Date()`"
output:
pdf_document:
toc: yes
toc_depth: 3
number_sections: true
documentclass: report
header-includes:
- \usepackage{titlesec}
- \titleformat{\chapter}{\normalfont\LARGE\bfseries}{\thechapter}{1em}{}
- \titlespacing*{\chapter}{0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
---
# Introduction
## Sub
### SubSub
# Methods
## Sub
### SubSub

If your only reason to use the report class is the page break before the table of contents, you could easily add it to the default class article:
---
title: The Force
subtitle: May it be with you
author: "Obi-Wan Kenobi"
date: "`r Sys.Date()`"
output:
pdf_document:
keep_tex: true
toc: yes
toc_depth: 3
number_sections: true
header-includes:
- \pretocmd{\tableofcontents}{\clearpage}{}{}
- \apptocmd{\tableofcontents}{\clearpage}{}{}
---
# Introduction
## Sub
### SubSub
# Methods
## Sub
### SubSub

Related

Regulate how many PDF pages is to be displayed per page in when knitting to PDF in Rmarkdown?

I have a rmarkdown document where I import a few PDFs, and I would like to display four PDF-import-pages per page in my knitted PDF.
---
title: "combinePages"
author: "xxx"
date: '2022-xx-xx'
output:
pdf_document:
toc: true
header-includes:
- \usepackage{pdfpages}
---
\includepdf[pages={-}]{pdfs/Lecture1.pdf}
\includepdf[pages={-}]{pdfs/Lecture2.pdf}
Can this be done in rmarkdown?
According to the manual of pdfpages,
nup => Puts multiple logical pages onto each sheet of paper. The syntax of this option is: nup=⟨xnup⟩x⟨ynup⟩. Where ⟨xnup⟩ and ⟨ynup⟩ specify the umber of logical pages in horizontal and vertical direction, which are arranged on each sheet of paper. (Default: nup=1x1)
So, four pdf pages from an imported pdf file can be knitted per page using nup=2x2 in the option of \includepdf.
---
title: "combinePages"
author: "xxx"
date: '2022-xx-xx'
output:
pdf_document:
toc: true
header-includes:
- \usepackage{pdfpages}
---
## Multiple Page
\includepdf[pages={1-}, nup=2x2]{lorem_ipsum.pdf}
\includepdf[pages={1-}, nup=2x2]{lorem_ipsum.pdf}
So A page of the rendered document looks like this,
Explore the manual for more options.

Bookmarks not working with RMarkdown (pdf) and titlesec

I was looking for a way to change heading format in RMarkdown (pdf) and found this code which works just fine.
---
output: pdf_document
header-includes:
- \usepackage[tiny]{titlesec}
\titleformat*{\section}{\center\bfseries}{}
---
However, the heading are not correct in the bookmarks of the document, i.e., all sections ends up a level lower than the previous (regardless of their actual level).
Here is an example.
---
output: pdf_document
header-includes:
- \usepackage[tiny]{titlesec}
\titleformat*{\section}{\center\bfseries}{}
---
# Level 1
# Level 1
## Level 2
### Level 3
# Level 1
## Level 2
And this is the resulting bookmarks.
Thank you,

YAML issue when knitting to pdf

I have a paper written in rnotebook, which I want to knit to pdf.
this is the beginning of it, including the YAML:
---
title: "Are shifts between points of view challenging for readers? An examination of readers' eye movements in response to Woolf's *To the Lighthouse* and *Mrs Dalloway*"
author: "Giulia Grisot, Kathy Conklin, Violeta Sotirova - The University of Nottingham"
date: '`r format(Sys.time(), "%d %B %Y")`'
output:
html_notebook:
fig_caption: yes
force_captions: yes
#highlight: pygments
number_sections: false
theme: readable
# csl: sage-harvard.csl
csl: apa.csl
bibliography: library.bib
link-citations: yes
nocite: |
#Grisot2018
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)
```
```{r, include=F}
library(tidyverse)
library(ggpubr)
```
# Abstract
The emergence of empirical approaches within stylistics has increased interest in how literary texts are processed by readers. Techniques of speech and thought representation represent an area ripe for empirical investigation in this respect, especially when these cause interpretative ambiguities.
I have installed tinytex, and I have got miktex installed and pandoc.
I have tried to just use the "knit to pdf" command in RStudio but it gives me this error and i don't know what to do
Error in yaml::yaml.load(..., eval.expr = TRUE) :
Scanner error: while scanning for the next token at line 4, column 31 found character that cannot start any token at line 4, column 31
Calls: <Anonymous> ... parse_yaml_front_matter -> yaml_load -> <Anonymous>
Execution halted
I think this is down to the formatting in your yaml. When I knitted your code R Studio did some re-formatting of the title, but in the process replaced the ' with " in your date, causing the error. I don't have your .bib file so I can't test your exact code, but the following worked for me:
---
title: Are shifts between points of view challenging for readers? An examination of
readers' eye movements in response to Woolf's *To the Lighthouse* and *Mrs Dalloway*
author: "Giulia Grisot, Kathy Conklin, Violeta Sotirova - The University of Nottingham"
date: '`r format(Sys.time(), "%d %B %Y")`'
output:
pdf_document: default
html_notebook:
fig_caption: yes
force_captions: yes
number_sections: no
theme: readable
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)
```
```{r, include=F}
library(tidyverse)
#library(ggpubr)
```
# Abstract

Using biblatex in R markdown without auto-creating "Reference" section

My header looks as follows and works perfectly as intended:
---
header-includes:
- \usepackage{float}
- \usepackage{wrapfig}
- \usepackage{graphicx}
- \usepackage[fontsize=12pt]{scrextend}
- \usepackage{fontspec}
- \renewcommand*{\bibfont}{\footnotesize}
- \usepackage[dvipsnames]{xcolor}
output:
pdf_document:
latex_engine: xelatex
fig_caption: true
citation_package: biblatex
bibliography: SPP.bib
mainfont: ArialMT
geometry: margin=0.75in
---
However, the reference section already gets populated by the section name "References". Is there a way to stop that automated insertion? Thanks.
The "References" section is automatically included if you define a bibliography. Here an excerpt from the template:
$if(biblatex)$
\printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$
$endif$
Do you only want to change "References" into something else. Then it would be sufficient to add biblio-title: ... to you YAML header. If you want to suppress it completely, you have remove the quoted part in a copy of the template and use this copy instead. You can find the location where the template is stored via:
system.file("rmd", "latex", package = "rmarkdown")
#> [1] "/usr/lib/R/site-library/rmarkdown/rmd/latex"
Typically there are several files there:
list.files(system.file("rmd", "latex", package = "rmarkdown"))
#> [1] "default-1.14.tex" "default-1.15.2.tex" "default-1.17.0.2.tex"
#> [4] "default.tex"
The one with the highest version number (here default-1.17.0.2.tex) is used.

Setting custom chapter numbering in Markdown

I'm creating an R Markdown document which outputs a PDF document. My YAML header is the following:
---
title: "Introduction"
author: "John Doe
date: "August 26, 2018"
mainfont: Pancetta Pro
documentclass: book
output:
pdf_document:
number_sections: true
df_print: kable
fig_caption: yes
fig_width: 6
highlight: tango
includes:
in_header: preamble.tex
latex_engine: xelatex
geometry: headheight=25pt, tmargin=25mm, bmargin=20mm, innermargin=20mm, outermargin=20mm
---
In the preamble.tex file I want to have the following LaTeX commands (which just modify the way the headers are displayed):
\renewcommand{\chaptermark}[1]{\markright{#1}}
\renewcommand{\sectionmark}[1]{}
\renewcommand{\subsectionmark}[1]{}
\usepackage{titlesec}
\titleformat{\chapter}[hang]{\Huge}{\bfseries\thechapter}{0.2pt}{\thicklines\thehook}[\vspace{0.5em}]
However, when these last lines are included in the preamble.tex I get an error when knitting the R Markdown file:
! Argument of \paragraph has an extra }.
<inserted text>
\par
l.1290 \ttl#extract\paragraph
Error: Failed to compile Template.tex
I can't figure out why it won't run. The contents of thepreamble.texfile are the following:
% !TeX program = lualatex
\usepackage{relsize} % To make math slightly larger.
\newcommand{\thehook}{%
\hspace{.5em}%
\setlength{\unitlength}{1em}%
\raisebox{-.5em}{\begin{picture}(.4,1.7)
\put(0,0){\line(1,0){.2}}
\put(.2,0){\line(0,1){1.7}}
\put(.2,1.7){\line(1,0){.2}}
\end{picture}}%
\hspace{0.5em}%
} %This creates the "hook" symbol at the beginning of each chapter.
\usepackage{anyfontsize}
\usepackage{fontspec}
\setmainfont{Pancetta Pro}
% We set the font for the chapters:
\newfontfamily\chapterfont{Pancetta Pro}
% And now for the sections:
\newfontfamily\sectionfont{Pancetta Pro}
\usepackage{fancyhdr}
\fancyhead{}
\fancyfoot{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhead[RO]{\large\sffamily\rightmark\thehook\textbf{\thepage}}
\fancyhead[LE]{\large\sffamily\textbf{\thepage}\thehook\rightmark}
\fancypagestyle{plain}{%
\fancyhf{}
}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markright{#1}}
\renewcommand{\sectionmark}[1]{}
\renewcommand{\subsectionmark}[1]{}
\fontsize{12}{20}\selectfont
\usepackage{titlesec}
\titleformat{\chapter}[hang]{\Huge}{\bfseries\thechapter}{0.2pt}{\thicklines\thehook}[\vspace{0.5em}]
When excluding the last 6 lines in the previous code there's no error and the pdf is created.
If you want to use titlesec together with rmarkdown you have to add
subparagraph: yes
to your YAML headers, c.f. several other answers.
The default LaTeX class used by rmarkdown is article, which has no chapters. You should add
documentclass: report
or
documentclass: book
to your YAML header.