Section header and landscape-oriented figure on same PDF page - r

Inside a knitr-generated PDF, I want to have the section title on the same page as a figure displayed in landscape format.
If I do this
---
title: "Untitled"
output: pdf_document
date: '2022-06-21'
header-includes:
- \usepackage{pdflscape}
---
# Section title
\begin{landscape}
```{r pressure, out.extra= 'angle=0', echo = F}
plot(pressure)
```
\end{landscape}
The plot appears on a different page than "Section title" as \begin{landscape} apparently starts a new page
But if I do this
---
title: "Untitled"
output: pdf_document
date: '2022-06-21'
header-includes:
- \usepackage{pdflscape}
---
\begin{landscape}
# Section title
```{r pressure, out.extra= 'angle=0', echo = F}
plot(pressure)
```
\end{landscape}
I am getting an error message
! You can't use `macro parameter character #' in vertical mode.
l.74 #
Section title
Error: LaTeX failed to compile sectionTitle.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See sectionTitle.log for more info.
Execution halted
Edit: this syntax, leaving empty lines around the section heading, is not working
---
title: "Untitled"
output: pdf_document
date: '2022-06-21'
header-includes:
- \usepackage{pdflscape}
---
\begin{landscape}
# Section title
```{r pressure, echo=FALSE}
plot(pressure)
```
\end{landscape}

Related

R Markdown: How to use icons

I would like to inlcude Icons at the beginning of my titles in an R markdown script. I found a CV template of a girl that does so, but this does not work for me:
https://github.com/loreabad6/R-CV/blob/master/CV.Rmd
'library(fontawesome)'
\faIcon{university}
I also tried: In `rmarkdown`, how to add icon in sentence?
`r icons::fontawesome("markdown")`
What do I need to do instead?
HTML
You can use the following code to add icons:
---
title: "Untitled"
author: "Author"
date: "2022-08-15"
output: html_document
---
```{r setup, include=FALSE}
remotes::install_github("mitchelloharawild/icons")
icons::download_fontawesome()
```
# This is my title `r icons::fontawesome("markdown")`
Output:
PDF
You can use the latex package fontawesome5. I had to install the package rsvg (just in console) before running the following code:
---
title: "Untitled"
author: "Author"
date: "2022-08-15"
output:
pdf_document:
keep_tex: true
header-includes:
- \usepackage{fontawesome5}
---
# This is my title `r icons::fontawesome("markdown")`
Output:

r - rmarkdown - yaml - Is it possible to include inline, internal document hyperlink in title?

is it possible to include an inline (internal document) hyperlink in the YAML title block of a RMarkdown document? Or is there a R package that allows this?
Below is what I am trying to do:
---
title: blah {#one1} and so on {#two2}
...
---
# Bibliography
1. Reference note to [explain](#one1) in title
2. Reference note to [explain](#two2) in title
Thank you.
The title is parsed as markdown, so you can use regular markdown link syntax in order to get the behavior you want.
---
title: 'There is a link in this title...[LINK](#anchor)'
author: "Jason Punyon"
date: "6/16/2020"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# Bibliography
<p id='anchor'>Here's where I went!</p>
You could also just put the link in manually...
---
title: 'There is a link in this title...LINK'
author: "Jason Punyon"
date: "6/16/2020"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# Bibliography
<p id='anchor'>Here's where I went!</p>

R Markdown keywords don't appear in the document

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
When knitting to PDF, keywords are sent to the file metadata but are not actually visible in the file. Source
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:
Add a LaTeX code to provide the \keyword command (\providecommand{\keywords}[1]{\textbf{\textit{Keywords---}} #1}) into YAML's header-includes key;
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

R Markdown: fancyhdr can't set head rule to 0 even after redefining the \headrulewidth command

I'm trying to make a quick thesis document/template, but the documents are not allowed to have a header line, just the page numbers. I can change what exists inside the header and footers (e.g. adding a page number at the top right hand of the page), but the rule won't go away.
I tried multiple variations of the following code (this being example document to try to isolate the problem):
---
title: "Test"
author: "TEst"
date: "February 14, 2018"
output: pdf_document
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \AtBeginDocument{\thispagestyle{fancy}}
- \rhead{\thepage}
- \cfoot{}
- \renewcommand{\headrulewidth}{0pt}
---
\renewcommand{\headrulewidth}{0pt}
\newpage
\renewcommand{\headrulewidth}{0pt}
# Hello
But no luck. The line is always there. I even tried the \renewcommand{\headrule}{} and it still shows up. I'm thinking this may be a pandoc error, but I'm not entirely sure. Could you guys provide some insight?
Edit: This code is now the exact test case I was using to troubleshoot. The actual document is included below as well.
---
output:
pdf_document:
fig_caption: yes
number_sections: yes
bibliography: library.bib
csl: methods-in-ecology-and-evolution.csl
urlcolor: black
linkcolor: black
fontsize: 12pt
geometry: margin = 1.2in
header-includes:
- \usepackage{placeins}
- \usepackage{fancyhdr}
- \usepackage{setspace}
- \usepackage{chngcntr}
- \usepackage{microtype}
- \onehalfspacing
- \counterwithin{figure}{section}
- \counterwithin{table}{section}
---
---
nocite: |
#Example1999, #Example2000
...
```{r global_options, include=FALSE}
knitr::opts_chunk$set(fig.path = 'figures/',
echo = FALSE, warning = FALSE, message = FALSE)
```
\pagenumbering{gobble}
```{r child = 'titlepage.Rmd'}
```
\newpage
```{r child = 'declaration.Rmd'}
```
\newpage
\pagestyle{fancy}
\fancyhead[LE,RO]{}
\fancyhead[LO,RE]{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\pagenumbering{roman}
\renewcommand{\headrulewidth}{0pt}
\fancyhead[CO,CE]{Abstract}
\renewcommand{\headrulewidth}{0pt}
\section*{Abstract}
\addcontentsline{toc}{section}{Abstract}
```{r child = 'abstract.Rmd'}
```
\newpage
\fancyhead[CO,CE]{Acknowledgements}
\section*{Acknowledgements}
\addcontentsline{toc}{section}{Acknowledgements}
```{r child = 'acknowledgements.Rmd'}
```
\newpage
\fancyhead[CO,CE]{Table of Contents}
\setcounter{tocdepth}{2}
\tableofcontents
\newpage
\pagenumbering{arabic}
\newpage
\fancyhead[CO,CE]{Introduction}
```{r child = 'chapter1.Rmd'}
```
\FloatBarrier
\newpage
\fancyhead[CO,CE]{Methods}
```{r child = 'chapter2.Rmd'}
```
\FloatBarrier
\newpage
\fancyhead[CO,CE]{Results}
```{r child = 'chapter3.Rmd'}
```
\FloatBarrier
\newpage
\fancyhead[CO,CE]{Discussion}
```{r child = 'chapter4.Rmd'}
```
\FloatBarrier
\newpage
\fancyhead[CO,CE]{List of Figures}
\addcontentsline{toc}{section}{List of Figures}
\listoffigures
\newpage
\fancyhead[CO,CE]{List of Tables}
\addcontentsline{toc}{section}{List of Tables}
\listoftables
\newpage
```{r child = 'appendix.Rmd'}
```
\FloatBarrier
\newpage
\fancyhead[CO,CE]{References}
# References
Edit 2: Solved it! By placing the commands into a .sty file and including that file in the header via the following
output:
pdf_document:
fig_caption: yes
number_sections: yes
includes:
in_header: test.sty
bibliography: library.bib
I have had extremely precise control over the document via the typical LaTeX syntax, so I'm making a .sty file that should hopefully let me (and others) write their dissertations in R Markdown!

Change the caption title of a figure in markdown

I'm currently writing a small report in German. Hence I want my figure caption titles to be changed from Figure 1 to Abbildung 1 and so on.
---
title: "Untitled"
author: "me"
date: '`r format(Sys.time(), "%d %B, %Y")`'
output:
pdf_document: default
---
```{r iris, fig.cap='Iris sepal lengths'}
hist(iris$Sepal.Length)
```
Question: How can I change the default figure title (not sure if it's actually called that way) in R Markdown?
If you are writing in any language other than English, you can change the language options of the outputted pdf with the lang YAML option. This will override all the captions, labels, table of contents etc.
---
output: pdf_document
lang: de
---
```{r iris, fig.cap='Iris sepal lengths'}
hist(iris$Sepal.Length)
```
Other language options include fr (French), it (Italian) etc. See http://pandoc.org/MANUAL.html#language-variables for more details.
Following the example from this question, you can define your own tex file where you can change figure caption defaults.
header.tex:
\usepackage{caption}
\captionsetup[figure]{name=Abbildung}
This is the main .Rmd file:
---
title: "Untitled"
author: "me"
date: '`r format(Sys.time(), "%d %B, %Y")`'
output:
pdf_document:
includes:
in_header: header.tex
---
```{r iris, fig.cap='Iris sepal lengths'}
hist(iris$Sepal.Length)
```

Resources