Split the title onto multiple lines? - r

In an R markdown document (html and presentations), is it possible to manually split the title onto multiple lines? I tried playing with pipes which produces orrendous output.
---
title: 'A title I want to split on two lines'
author:
date:
output:
ioslides_presentation
---

Examples for adding an abtract show the use of pipes | to break lines and include paragraphs. This works as well for the title and other yaml elements. For an abstract or title:
---
abstract: |
What works for the abstract.
Works for the title, too!
title: |
| title
| subtitle
output: pdf_document
---

For an HTML output just us the <br> tag while if your output is a PDF or PDF presentation standard LaTeX code to break line given by \\ should work.
Example
---
title: 'A title I want to <br> split on two lines'
author:
date:
output:
ioslides_presentation
---
For PDF
Just to rule out possibilities, I've tried to put \\ or \newline, both do not split, so for PDF seems to be a little bit tricky. \linebreak stop knitr parsing. Maybe another user can solve this question for knitr PDFs.

For PDF output, experimentation revealed that the following works:
---
title: 'A title I want to \nsplit on two lines'
author:
date:
output: pdf_document
---
That is two spaces followed by \n.

Related

Header and footer in quarto qmd to pdf

Anyone a suggestion how to set the header and footer of a #quarto .qmd #rstats pdf?
I tried this, but no footer shows:
---
title: "Untitled"
format:
pdf:
include-in-header:
text:
\usepackage{fancyhdr}
---
\fancyfoot[L]{Footer text}
# Chapter ONE
text
\newpage
# Chapter TWO
Can I use fancyhdr? If yes, how? If not, what then? Thanks!
Yes, It is possible to use fancyhdr (see the answer by #Julian).
But also keep in mind that, Quarto uses KOMA-Script classes (scrartcl by default) and KOMA-Script suggests using scrlayer-scrpage latex package for handling header and footers instead of fancyhdr. See the manual chapter 05, p. 253.
---
title: "Untitled"
format:
pdf:
include-in-header:
text: |
\usepackage{scrlayer-scrpage}
\rohead{Header text}
\lofoot{Footer text}
---
# Chapter ONE
text
\newpage
# Chapter TWO
You may also want to go through this question and the corresponding answer on Tex StackExchange.
You are not that far away from the solution. If you want to use fancyhdr, this could work (note that you need to add text: | in order to have multiple lines of latex code):
---
format:
pdf:
include-in-header:
text: |
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[C]{Header text}
\fancyfoot[L]{Footer text}
---
# Chapter ONE
text
\newpage
# Chapter TWO

How can I force a line break in rmarkdown's title for beamer output?

I have a quite long title in a rmarkdown document and I would like to force a line break in a specific position.
Minimum example:
---
title: "Quite long title want the * line break at the asterisk"
output: beamer_presentation
---
I have tried: \n, \newline, \ and a manual line break. None of them seem to work.
I believe it has to be quite straightforward but I haven't been able to find a solution.
You'll have to escape the \:
---
title: "Quite long title want the \\newline line break at the asterisk"
output:
beamer_presentation:
keep_tex: true
---
test

Include an extra section of text/hyperlink in YAML-Header section of Rmarkdown document

I'm writing a document in RMarkdown and have hopefully a fairly straightforward query about including extra information in the header section.
My Header section of the rmd looks like:
---
title: "My R-Markdown Document"
author: "[My name here](a hyperlink to my institutional page)"
output: html_document
---
I'm trying to add a simple extra line after my name which includes my Twitter handle
I tried cheating by adding it as an abstract....:
---
title: "My R-Markdown Document"
author: "[My name here](a hyperlink to my institutional page)"
abstract: "[I'm on Twitter](hyperlink)"
output: html_document
---
But that displays the heading Abstract before the extra information i.e I get
"Abstract: I'm on Twitter"
Whereas the desired output would be
Title Text
Name (Hyperlink)
I'm on Twitter (Hyperlink)
Anyone know how to get this to work?
I've looked at PANDOC Guide and other examples and I've tried all sorts of things calling it description, institute but none of these seem to render except for Abstract which has the issue highlighted above.
NB: Modified-extra query
This works for an HTML output but doesn't seem to if output == PDF
Any suggestions in that realm also welcomed!
There are a couple of ways to render the RMarkdown YAML header content for a single field on multiple lines. The following examples work for me in both pdf and html formats:
Using two spaces followed by \n
---
title: "My R-Markdown Document"
author: "[My name here](a hyperlink to my institutional page) \n[I'm on Twitter](hyperlink)"
output:
pdf_document: default
html_document: default
---
Using the | operator
---
title: "My R-Markdown Document"
author: |
| [My name here](a hyperlink to my institutional page)
| [I'm on Twitter](hyperlink)
output:
pdf_document: default
html_document: default
---
Using html line break <br> (works for html, not pdf)
---
title: "My R-Markdown Document"
author: "[My name here](a hyperlink to my institutional page)<br><br>[I'm on Twitter](hyperlink)"
output: html_document
---
Note, including additional information like this in the author field may not be ideal as the additional information will also be included in the rendered html author metadata:
<meta name="author" content="My name here I’m on Twitter" />
These questions might also be helpful:
In YAML, how do I break a string over multiple lines?
Split the title onto multiple lines?

Setting document title in Rmarkdown from parameters

I've got an Rmarkdown template that works well, and I've parameterized it so I can generate variants of the same report from different data sources. However, I'd like to change the title of the report in each case. How do I do that?
Here's the YAML header I have so far:
---
title: "My Title"
author: "Me, Inc."
date: "August 4, 2015"
output: pdf_document
params:
title: default
---
I've tried using params=list(title="ASDF") in the call to rmarkdown::render, and although my code can see that variable, it doesn't change the title. I've also tried using r params$title in the YAML, but that gives a syntax error.
Is there something else I should be trying? Thanks!
Try to use a second YAML metadata block, and put the parameterized metadata in there.
I got the following code to work as expected (i.e., producing a document title from the list of params):
---
output: html_document
params:
set_title: "My Title!"
---
---
title: `r params$set_title`
---
The RMarkdown documentation notes that YAML metadata blocks are combined by Pandoc. Use the first block to define the parameter set, and the second one to use the parameters as metadata. Knitr will execute the R code to interpret the parameters in the second block.Then Pandoc will merge the metadata blocks together.
Update (2017):
This can be accomplished in a single block, like so:
---
output: html_document
params:
set_title: "My Title!"
title: "`r params$set_title`"
---
This works because the title comes after the params definition. I put quotes around the in-line R code to prevent "Scanner errors".
This is a more simplified approach to the dynamic title challenge.
Decouple title from the top declaration like this:
From this:
---
title: "Sample Title"
output: pdf_document
---
To This:
---
output: pdf_document
---
```{r}
title_var <- "Sample Title"
```
---
title: `r title_var`
---
Within the R code chunks, declare title_var. Now the title is held within a variable. Hope this helps!
Adding this answer as it helps in making R markdown titles dynamic.
Just use !r followed by the object name defined (test_title in the case below) to make the title dynamic.
---
output: pdf_document
params:
set_title: !r test_title
---
---
title: `r params$set_title`
---

First-line paragraph indenting in PDFs using R Markdown

I'm hoping this is a question with a simple answer. I am using Rmarkdown/knitr to author a PDF document (in RStudio). Many LaTeX classes (like article) automatically indent the first line of a paragraph of text, but Rmarkdown does not, nor can I figure out a way to do so.
Here's a simple example:
---
title: "minimal"
author: "prison rodeo"
output: pdf_document
---
This is an R Markdown document.
I would like this paragraph to be first-line indented, but it is not.
Using > indents the entire paragraph, which is not what I'm looking for. I've tried spaces/tabs at the beginning of each paragraph, and using \indent; neither seems to work. Any ideas?
The default Pandoc template includes an indent argument. If set to true, paragraphs start with an indentation.
----
title: "Title"
author: "Me"
output: pdf_document
indent: true
----
I believe the following in your YAML header will work the same and has the advantage of still compiling should you decide to knit your document to an HTML file (though, I haven't tested this).
----
title: "Title"
author: "Me"
header-includes:
- \setlength\parindent{24pt}
output:
pdf_document
----
If what you're after happens to be the default settings in other regards as well, you might also be interested in setting the \parskip option to its default setting, since it is otherwise set to {6pt plus 2pt minus 1pt}
header-includes:
- \setlength\parindent{24pt}\setlength{\parskip}{0.0pt plus 1.0pt}

Resources