How do I format a TOC in bookdown using latex? - latex

I am using bookdown with latex styling to make a report that contains headers, footers and section formatting. When i knit the report all pages have the correct formatting except the TOC.
MWE is below. There are no headers and the default section title formatting is not applied to the contents page.
index.Rmd
---
title: "A Quick Test"
author: "Jack Jill"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
documentclass: article
description: "This is a minimal example of a report."
papersize: a4
output:
bookdown::pdf_document2:
includes:
in_header: in_header.tex
before_body: before_body.tex
toc: true
geometry: top=20mm,bottom=60mm,footnotesep=10mm,left=24mm,right=30mm
---
\newpage
# **HEADING 1**
## **Subheading**
Here is some text for the document.
# **HEADING 2**
Here is some text for the document.
# **HEADING 3**
Here is some text for the document.
in_header.tex
%Essential packages
\usepackage{graphicx, color}
\usepackage{multirow}
\usepackage[T1]{fontenc}
\usepackage{titlesec}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{etoolbox}
\usepackage{tocloft}
\definecolor{airforceblue}{rgb}{0.36, 0.54, 0.66}
\definecolor{aliceblue}{rgb}{0.94, 0.97, 1.0}
\definecolor{amber}{rgb}{1.0, 0.75, 0.0}
\definecolor{amaranth}{rgb}{0.9, 0.17, 0.31}
\definecolor{amber}{rgb}{1.0, 0.75, 0.0}
\definecolor{black}{rgb}{0, 0, 0}
% This changes all section headings
\titleformat*{\section}{\bfseries\Large\itshape}
\titleformat*{\section}{\color{airforceblue}}
% Turn off default title page so I can make my own
\let\oldmaketitle\maketitle
\AtBeginDocument{\let\maketitle\relax}
before_body.tex
\pagestyle{fancy}
\fancyhead{}
\fancyhf{}
% Page layout
\parindent 0pt
\parskip 0pt
% Make custom page numbers
\cfoot{Page \thepage \hspace{1pt} of \pageref{LastPage}}
% Make a pretty header for every page
\fancyhead[L]{\includegraphics[width=3.5cm]{logo.png}}
\fancyhead[R]{\raisebox{1.6cm}{\color{amaranth}www.website.com.au}}
% Make the title page here
\setlength\headheight{68pt}
\vspace*{2.5cm}
\fontsize{36pt}{42pt}\selectfont\bfseries\color{airforceblue}
MY REPORT TITLE
\vspace*{0.5cm}
\color{airforceblue}
{\bfseries\huge{ SUBTITLE } }
\vspace*{1.0cm}
\colorbox{amber}{\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\bfseries\huge\strut\textcolor{aliceblue}{ AUTHOR NAME } }}
% replace default title page with my new one
\let\maketitle\oldmaketitle
% end page
\clearpage
% Set default fonts for doc
\fontsize{10}{12}\selectfont
\fontfamily{qcr}\selectfont
\setlength{\headheight}{98pt}
\color{black}
% Manually adding TOC does not add header either
% \tableofcontents
% \addcontentsline{toc}{section}{\contentsname}

The toc page uses the plain page style. If your version of the fancyhdr package is reasonable new, you can change the plain page style to be the same as your fancy page style with the simple command
\fancypagestyle{plain}[fancy]{}
---
title: "A Quick Test"
author: "Jack Jill"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
documentclass: article
description: "This is a minimal example of a report."
papersize: a4
output:
bookdown::pdf_document2:
toc: true
toc_depth: 2
keep_tex: true
includes:
in_header: in_header.tex
before_body: before_body.tex
header-includes: \fancypagestyle{plain}[fancy]{}
geometry: top=20mm,bottom=60mm,footnotesep=10mm,left=24mm,right=30mm
---
\newpage
# **HEADING 1**
## **Subheading**
Here is some text for the document.
# **HEADING 2**
Here is some text for the document.
# **HEADING 3**
Here is some text for the document.

Related

How to render citation within a beamer subtitle in Rmarkdown

I'm trying to combine both adding subtitles to beamer frames and rendering citations inside them in Rmarkdown. In LaTeX I've been able to do this with the following code:
\begin{frame}{Kontrastive Analyse: Russisch-Deutsch}
\framesubtitle{Phonetik und Phonologie kontrastiv: Russisch und Deutsch \parencite{kuemmelPhonetikundPhonologieRussischundDeutsch2017}}
...
\end{frame}
However, I'm having a hard time doing the same in Rmarkdown, where I have the bibliography defined in the YAML on the one hand and on the other hand also defined in the custom tex header.
So far, I've explicitly written the frame subtitle as LaTeX code (because I currently don't know how subtitles can be made in Rmarkdown beamer format; pipe character doesn't seem to work) and within the subtitle code use biblatex's \parencite{}, as follows
\framesubtitle{with a subtitle \parencite{kuemmelPhonetikundPhonologieRussischundDeutsch2017}}
So while the rest of citations written in markdown format (i.e. [#citekey]) are rendered without problem, citations within subtitles aren't. How can I solve this?
Here's the code so far:
---
title: "Presentation Title"
subtitle: "Subtitle"
author: |
| [Name]
| \scriptsize [Email]
institute: |
| [Institution]
| [Faculty]
| [Institute/Department]
| [Seminar]
| [Professor]
| [Semester]
date: \today
output:
beamer_presentation:
latex_engine: xelatex
keep_tex: TRUE
slide_level: 3
includes:
in_header: "myacademic-preamble.tex"
classoption: aspectratio=169
link-citations: true
bibliography: '/Users/marco-andres/Documents/Zotero+Pandoc/MyLibrary.bib'
csl: '/Users/marco-andres/Documents/Zotero+Pandoc/institut-slawistik-hu-berlin.csl'
---
\frametitle{Table of Contents}
\tableofcontents
# This is a dividing slide
## This is another dividing slide (subsection shown in TOC)
### Here's an individual slide
\framesubtitle{with a subtitle (Kümmel 2017)}
# Bibliography
\printbibliography
The custom .tex relevant for LaTeX-style bibliography is:
%Bibliography and language
\usepackage[english]{babel} %section and bibliography langauge
\usepackage{csquotes}
\usepackage[style=authoryear, sorting=nyt]{biblatex} %bibliography style
\addbibresource{MyLibrary.bib} %bib file

Rmd: Hide FOOTER on title&content page

I am creating a RMarkdown template of Beamer slides and use the metropolis theme as a basis.
Now I want to add a footer with some text on the left side and the slide number as fraction on the right side. That works. Furthermore, the whole footer should not be shown on the title & content page. How can I control where the foot line is shown?
This is my (minimal working example):
slides.rmd
---
title: "Title"
subtitle: "Subtitle"
author: "Simon"
institute: "RUB"
date: "September 22, 2021"
output:
beamer_presentation:
keep_md: true
keep_tex: no
latex_engine: xelatex
#theme: metropolis
includes:
in_header:
#- toc.tex
slide_level: 2 # which header level should be printed as slides
incremental: no
header-includes:
- \usetheme[numbering=fraction]{metropolis}
- \definecolor{beaublue}{rgb}{0.74, 0.83, 0.9}
- \setbeamertemplate{frame footer}{\tiny{\textcolor{beaublue}{Conference 56. Jahrestagung der DGSMP, 2021}}}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Content
\tableofcontents[]
# Level I
Test
## Slide with Bullets
- Bullet 1
- Bullet 2
- Bullet 3
# Slide with R Output
```{r cars, echo = TRUE}
summary(cars)
```
I know that it would be possible in Latex via the begingroup & endgroup command combined with the plain-option ({}) used on \setbeamertemplate{footline}:
\documentclass{beamer}
\setbeamertemplate{footline}[frame number]
\begin{document}
\begin{frame}
normal frame
\end{frame}
\begingroup
\setbeamertemplate{footline}{}
\begin{frame}
without footline
\end{frame}
\endgroup
\begin{frame}
normal frame
\end{frame}
\end{document}
But I don't know how to implement it in RMarkdown.
To remove the footline from your title and toc page, you can use the same trick as in https://topanswers.xyz/tex?q=1004#a1198
Add the following to your header includes:
\makeatletter
\def\ps#navigation#titlepage{%
\setbeamertemplate{footline}{}
\#nameuse{ps#navigation}
}
\addtobeamertemplate{title page}{\thispagestyle{navigation#titlepage}}{}
\pretocmd{\tableofcontents}{\thispagestyle{navigation#titlepage}}{}{}
\makeatother
(please also note that the syntax \tiny{...} is wrong. This macro is a switch and does not take an argument. You can instead use {\tiny ...}
---
title: "Title"
subtitle: "Subtitle"
author: "Simon"
institute: "RUB"
date: "September 22, 2021"
output:
beamer_presentation:
keep_md: true
keep_tex: no
latex_engine: xelatex
#theme: metropolis
includes:
in_header:
#- toc.tex
slide_level: 2 # which header level should be printed as slides
incremental: no
header-includes:
- \usetheme[numbering=fraction]{metropolis}
- \definecolor{beaublue}{rgb}{0.74, 0.83, 0.9}
- \setbeamertemplate{frame footer}{{\tiny\textcolor{beaublue}{Conference 56. Jahrestagung der DGSMP, 2021}}}
- \makeatletter
- \def\ps#navigation#titlepage{\setbeamertemplate{footline}{}\#nameuse{ps#navigation}}
- \addtobeamertemplate{title page}{\thispagestyle{navigation#titlepage}}{}
- \pretocmd{\tableofcontents}{\thispagestyle{navigation#titlepage}}{}{}
- \setbeamertemplate{section in toc}{\leavevmode\inserttocsectionnumber. \inserttocsection\par}
- \makeatother
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Content
\tableofcontents[]
# Level I
Test
## Slide with Bullets
- Bullet 1
- Bullet 2
- Bullet 3
# Slide with R Output
```{r cars, echo = TRUE}
summary(cars)
```

Rmarkdown Latex citation (Harvard style) within footnote

I am writing my thesis in Rmarkdown and Latex with a seperate literature.bib file that contains the bibtex sources. I now have a footnote and I would like to have a citation like in the normal text, but within the footnote. Is there any package to achieve that? When i just try it, like I would have a citation in the normal text, the footnote stops beeing a footnote when i render to pdf. The citation style I use is the Harvard citation style, so only something like this appears and should appear in the footnote:
The rest of information is than provided under the heading References at the end of the document. Thanks in advance! I appreciate any help...!
Here a minimal reproducable example:
--> This is the code for the main .rmd file
---
output:
bookdown::pdf_document2:
toc: no
papersize: a4
geometry: margin = 1in
fontsize: 11pt
bibliography: literatur.bib
---
#TEST
This is just an example #test.\footnote{I would also like to have a citation here in this footnote!!}
\newpage
# References
<div id="refs"></div>
-->This is the code for the literatur.bib file
#online{test,
author = {PACER},
title = {Service Center},
url = {https://pcl.uscourts.gov},
urldate = {2021-09-10}
}
Hope that is helpful?!
If you use markdown syntax for the footnote, you can also insert the citation via markdown syntax:
---
output:
bookdown::pdf_document2:
toc: no
papersize: a4
geometry: margin = 1in
fontsize: 11pt
bibliography: literatur.bib
---
#TEST
This is just an example #test.^[I would also like to have a citation here in this footnote!! See [#test]]
\newpage
# References
<div id="refs"></div>

Fancyhead for unnumbered appendix in R Markdown knit to pdf

A question about fancyhdr in R Markdown knitting to pdf.
Can anyone help me to fix the header for the appendix? I have numbered sections in the document, and the fancyhead for pages with the numbered sections is oke. But for the unnumbered appendix, it keeps showing the last numbered section, where I just want the title of the current unnumbered appendix to be shown. Code example below. Thanks!
---
title: "Example"
output:
pdf_document:
number_sections: true
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
---
\newpage
# Chapter
\newpage
# Appendix {-}
You can adjust the header like this:
---
title: "Example"
output:
pdf_document:
number_sections: true
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
---
\newpage
# Chapter
\newpage
# Appendix {-}
\markboth{something here}{something there}

Include after_body in toc with bookdown

I am creating a pdf book, and want to include the after_body header in the toc. I use the following yaml:
---
author: "name"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
geometry: "left=4cm,right=3cm,top=3cm,bottom=3cm"
subparagraph: true
output:
bookdown::pdf_book:
toc: false
citation_package: natbib
includes:
before_body: frontpage.tex
after_body: after_body.tex
in_header: preamble.tex
fontsize: 11pt
linestretch: 1.2
documentclass: book
bibliography: [packages.bib, library.bib]
biblio-style: apalike
link-citations: yes
---
In the after_body.tex i have the following:
\backmatter
\begin{titlepage}
\LARGE
\textbf{Enclosed articles I - III}
\end{titlepage}
How do I include the "Enclosed articles I - III" in the toc? I create the toc with \tableofcontents before \mainmatter in the index.Rmd file.
Edit: I also noticed that bookdown creates an empty page with a page number after the \titlepage latex environment. This also happens in the frontpage.tex. Is there any way to remove the numbers on these pages?
I managed to do this by changing the \textbf to \chapter, and include this in the preamble.tex:
\usepackage{fancyhdr}
\pagestyle{fancy}
\setlength{\headheight}{13.6pt} % as requested by fancyhdr's warning
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}}
\makeatletter
\renewcommand{\chaptermark}[1]{%
\if#mainmatter
\markboth{Chapter \thechapter{}: #1}{}%
\else
\markboth{#1}{}%
\fi
}
As taken from this post

Resources