Include instructor and course name in the YAML header - r

In the cover page of the term paper I should include some information as instructor’s name, name of the course, and name of the university.
I added the instructor’s name and the course name and into the YAML header, but they are not shown in the PDF. Moreover, I do not exactly know how to include the name of the PDF, I cannot find a list of tags for the YAML header.
If possible, I would like to solve the problem without installing much software and packages, as it increases the cost of reproducing the code on another computer.
Here the YAML header I used:
---
title: "Cool title"
author: "My Self"
date: "31st February 2023"
instructor: "Dr. Professor"
course: "Econ 101"
output:
pdf_document:
latex_engine: xelatex
editor_options:
chunk_output_type: console
abstract: "This is my abstract, it will be about 100 words"
---
# Introduction #

Related

Insert r inline code in abstract with rticles journal template

I am using a r-markdown rticles journal template to prepare a manuscript. Almost all rticles templates place the abstract in the YAML header section. I am not able to insert inline r code to the abstract in YAML. I could move the abstract to the text section to insert inline r code. However, the final format would also change. In biomedical field, abstracts often include some numbers from data. What is the best way to add r inline code to the abstract with a rticles journal template? Thanks
Edit: I have just realized that r code for analysis can be placed before the YAML header section. This will solve my problem. Here is a shorten version using Elsevier Journal template:
```{r, echo=FALSE, include=FALSE}
n <- length(mtcars$mpg)
```
---
title: Short Paper
author:
- name: Alice Anonymous
email: alice#example.com
affiliation: Some Institute of Technology
footnote: Corresponding Author
address:
- code: Some Institute of Technology
address: Department, Street, City, State, Zip
abstract: |
There are `r n` observations.
journal: "An awesome journal"
date: "`r Sys.Date()`"
bibliography: mybibfile.bib
csl: elsevier-harvard.csl
output: rticles::elsevier_article
---
However, the journal template in the YAML header is no longer working. Now, I am back to where I started.

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?

R markdown / bookdown - how to switch to rticles?

Input data
I prepared an example Rmd file with references to figure, table and equation, setting as an output 'bookdown::pdf_document2'. It compiles without errors to PDF.
I placed it on dropbox:
https://www.dropbox.com/sh/zmu0a4wq95ywssv/AAD-nHlkDiLknLk2NVR4Xup3a?dl=0
Question
Now I wish to set as an output format 'rticles::elsevier_article'
How can I do that?
Issue
When I change output line from:
bookdown::pdf_document2
to
rticles::elsevier_article
I'm receiving an error message.
Even if I remove other parameters from output:
I still receive an error message:
! Undefined control sequence.
Accented characters when input "as is" do not appear to behave well with elsevier_article. See suggestions below.
Bare-bones document
Here is a bare-bones document using rticles::elsevier_article:
---
title: "Sample document"
author:
- name: "Mateusz Kędzior"
affiliation: Some Institute of Technology
email: Mateusz#example.com
footnote: Corresponding Author
- name: Żąćł Źęń
csl: https://www.zotero.org/styles/geoderma
output:
rticles::elsevier_article:
citation_package: natbib
keep_tex: yes
number_sections: yes
toc: no
keywords: keywordA, keywordB
abstract: This is a sample abstract \newline This is the second line of abstract.
---
Hello world.
which renders with no complaints:
Reference with accents
Now, we wish to add a reference with accents. We follow the answer here: https://tex.stackexchange.com/questions/57743/how-to-write-%C3%A4-and-other-umlauts-and-accented-letters-in-bibliography. I imported your bibliography into Zotero, and then exported the item with a "Central European (ISO)" encoding (not UTF-8) to obtain
#article{kedzior_this_2018,
title = {This is sample title only {\k A} {\L }},
volume = {99},
url = {http://megooglethat.com/},
journal = {Some journal},
author = {K{\k e}dzior, Mateusz and {\'Z}{\k e}{\'n}, {\.Z}{\k a}{\'c}{\l }},
year = {2018},
keywords = {keywordC},
pages = {21 -- 31}
}
The R Markdown document now becomes
---
title: "Sample document"
author:
- name: "Mateusz Kędzior"
affiliation: Some Institute of Technology
email: Mateusz#example.com
footnote: Corresponding Author
- name: Żąćł Źęń
csl: https://www.zotero.org/styles/geoderma
output:
rticles::elsevier_article:
citation_package: natbib
keep_tex: yes
number_sections: yes
toc: no
biblio-files: bibliography2.bib
keywords: keywordA, keywordB
abstract: This is a sample abstract \newline This is the second line of abstract.
---
## Citations and references
Let me cite an article: [#kedzior_this_2018]
# References
I then knited this in RStudio, but realised that I had to get the tex output and rebuild it (outside of RStudio) to get the desired output
Other problems
For accented characters in figure captions, encode them accordingly (as with the bibliography). You may find http://w2.syronex.com/jmr/latex-symbols-converter helpful. In addition, to the best of my knowledge bookdown style cross-referencing does not work with rticles. If you have follow-up questions, you may get more helpful answers if you break your question down into smaller chunks.
I've added a bit of updated material to the commenthttps://github.com/rstudio/rticles/issues/92#issuecomment-402784283 where it states (may be updated):
output:
bookdown::pdf_document2:
base_format: rticles::elsevier_article
number_sections: yes
such that the way I've had this work is using pdf_book versus pdf_document2:
output:
bookdown::pdf_book:
base_format: rticles::elsevier_article
number_sections: yes
This allows for figure and table referencing within an rticles document.

R markdown / bookdown - how to display keywords below an abstract?

I defined keywords in the .Rmd file, but they are not visible in the output PDF.
Current Output
Expected results
Current .Rmd
First lines of .Rmd file looks as follows:
---
title: "No keywords within the output file"
abstract: "This is sample text for abstract. Generally speaking, I would like to show keywords list below an abstract (as in case of the linked example)"
keywords: "keywordA, keywordB"
author: "Mateusz Kędzior"
output:
bookdown::pdf_document2:
keep_tex: true
number_sections: yes
toc: false
base_format: rticles::elsevier_article
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Elsevier article
This is an R Markdown document.
I'm trying to prepare an Elsevier article.
I wonder if base_format is actually doing any work in your example (the output looks the same with and without base_format). Since base_format is an argument to pdf_book, consider changing your YAML header to
---
title: "No keywords within the output file"
author:
- name: "Mateusz Kędzior"
abstract: "This is sample text for abstract. Generally speaking, I would like to show keywords list below an abstract (as in case of the linked example)"
keywords: "keywordA, keywordB"
output:
bookdown::pdf_book:
keep_tex: true
number_sections: yes
toc: false
base_format: rticles::elsevier_article
---
which gives you the following output:
Alternatively, add keywords to the abstract:
abstract: "This is sample text for abstract. Generally speaking, I would like
to show keywords list below an abstract (as in case of the linked example) \\par
\\textbf{Keywords:} a, b"
to get

R Markdown ioslides institution name [duplicate]

How to add author affiliation in a new line in an rmarkdown beamer presentation?
---
title: "This is the title"
author: "Author"
date: "Thursday, April 09, 2015"
output: beamer_presentation
---
## Slide with Bullets
- Bullet 1
- Bullet 2
- Bullet 3
The desire title slide should be
This is the title
Author
Affiliation
Thursday, April 09, 2015
If you use pipes | you can break the author line into multiple lines:
---
title: "The title"
author: |
| The author
| The affiliation
date: "9 April 2015"
output: beamer_presentation
---
Output:
Edit (can we play with the title and author/affiliation fonts?):
If you want to change the different font sizes, I recommend playing with the includes: in_header option of your presentation's header (check this RStudio link for specifics).
This points to a simple .tex file on your computer where you can add LaTeX commands specifically for your presentation's preamble. You could therefore have a file called preamble.tex in your Desktop, and use the \setbeamerfont{XX}{size={\fontsize{YY}{ZZ}}} command, where XX is the specific thing you want to change (title, author); YY is the font size to apply; and ZZ is the skip line (in pt) (also see this link for more details).
So for your example, we have:
preamble.tex file at your Desktop (or wherever you want) containing just two lines:
\setbeamerfont{title}{size={\fontsize{30}{25}}}
\setbeamerfont{author}{size={\fontsize{5}{20}}}
Your foo.Rmd file:
---
title: "The title"
author: |
| The author
| The affiliation
output:
beamer_presentation:
includes:
in_header: ~/Desktop/preamble.tex
---
## R Markdown
This is an R Markdown presentation.
Markdown is a simple formatting syntax for
authoring HTML, PDF, and MS Word documents.
And the output will be:
and you should be able to have multiple authors and institutions
title: This is the title
author:
- Author Juan$^1$
- Author Tu$^2$
institute:
- $^1$Juans Casa
- $^2$Tus Place
date: "Thursday, April 09, 2015"
output:
beamer_presentation
The proper way to deal with affiliation in beamer is through \institute{} (see this answer on tex.SE).
Current solution (pandoc version >= 1.17)
Starting with pandoc 1.17, the institute field is present in the default beamer template, so all you need to do if you have the proper version is:
---
title: "This is the title"
author: "Author"
institute: "Affiliation"
date: "Thursday, April 09, 2015"
---
Old answer
Might be needed if you use an older pandoc version (< 1.17) or while rmarkdown's default beamer template has not been updated.
To make this work with pandoc, you could edit your beamer template. If you have not edited it yet, you can create it with:
pandoc -D beamer > ~/.pandoc/templates/default.beamer
Then, open the file and add this after the author information:
$if(institute)$
\institute[]{$institute$}
$endif$
Finally, add the institute option to your yaml:
---
title: "This is the title"
author: "Author"
institute: "Affiliation"
date: "Thursday, April 09, 2015"
---
If you are using rmarkdown, you may have to specify the template:
---
title: "This is the title"
author: "Author"
institute: "Affiliation"
date: "Thursday, April 09, 2015"
output:
beamer_presentation:
template: ~/.pandoc/templates/default.beamer
---
There are two advantages to using this over a multiline author.
some beamer theme use the author field and/or the institute field, for instance to repeat it at the bottom of each slide. A multiline author would mess this up.
this allow for a finer control of the title slide elements: you can have a different font family and size for author and affiliation information for instance:
\setbeamerfont{institute}{size={\fontsize{5}{20}}}

Resources