Is it possible to define a letterhead header in Rmarkdown? - r

R gurus,
I am struggling to design a letterhead template in Rmarkdown for a massive mail merge project.
What I ideally need is something like following:
Question is if the header can be defined in YAML? The code might look something like following:
---
output:
pdf_document:
fig_caption: false
logo: logo.png
institute: UNIVERSITY OF CALIFORNIA
name: Prof. Jones
address: Mathematics Search Committee
Department of Mathematics
University of California
Berkeley, California 12345
email: pj#uc.ac
latex_engine: pdflatex
fontfamily: mathpazo
fontsize: 11pt
# spacing: double
endnote: no
---

---
title: "Prof. Jones \nDepartment \nUniversity \nState \nEmail"
output: pdf_document
editor_options:
chunk_output_type: console
header-includes:
- \usepackage{titling}
- \usepackage{graphicx}
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \pretitle{\begin{flushright}\LARGE\includegraphics[width=8cm]{logo.jpg}\\[\bigskipamount]}
- \posttitle{\end{flushright}}
---
Add your logo to where it has {logo.jpg} and the width might need altering as well.
Bit of a workaround using double space and \n to add a line break to the heading to create the address.
flushright right aligns the logo and title then.

Related

How to add page numbers on rmarkdown beamer slide under theme: "boxes"?

Using rmarkdown beamer, I try to add slide number at the bottom of each slide but keep failing. Is there anyway I can add slide number on each page under beamer theme called "boxes"?
---
title: "Big Business"
author: |
| Mr. Bean
| Sunny College
output:
beamer_presentation:
theme: "boxes"
citation_package: natbib
biblio-style: apalike
incremental: TRUE
header-includes:
- \usepackage{makecell}
- \usepackage{booktabs}
- \usepackage{adjustbox}
---
# Motivation
Big business
# Motivation 2
Small business
The boxes theme has a special syntax to add things to the footline:
\addfootbox{normal text}{\hfill\insertframenumber\quad}
(replace <normal text> with any other beamer colour you like)
MWE:
---
title: "Big Business"
author: |
| Mr. Bean
| Sunny College
output:
beamer_presentation:
theme: "boxes"
citation_package: natbib
biblio-style: apalike
incremental: TRUE
header-includes:
- \usepackage{makecell}
- \usepackage{booktabs}
- \usepackage{adjustbox}
- \addfootbox{normal text}{\hfill\insertframenumber\quad}
---
# Motivation
Big business
# Motivation 2
Small business

How to make R Markdown links with boxes like LaTeX documents?

First, I have a .Rmd file using knitr to generate a pdf, it only contains a link:
---
title: "My Title"
author: "my name"
date: "2020/2/6"
output: pdf_document
linkcolor: blue
urlcolor: blue
citecolor: blue
---
[Stack Overflow](https://stackoverflow.com/)
and output is :
How can I change its pattern to default LaTeX style like:
Whatever it is a link, url or a cite, how to change it to LaTeX style with red or green boxes above?
Thanks!
Normally these boxes are shown by default. Unfortunately rmarkdown disables them, but you can undo the the changes made by rmarkdown:
---
title: "My Title"
author: "my name"
date: "2020/2/6"
output:
pdf_document:
keep_tex: true
header-includes:
- \hypersetup{colorlinks = false,pdfborder={1 1 1}}
---
[Stack Overflow](https://stackoverflow.com/)

Formatting issue when creating page header in rmarkdown

I am trying to learn Rmarkdown, but there is something that's quite elusive. I am trying to put my name at the top of every page of the PDF I print, however I also get the various headers from the text in the markdown file in the header, and it often overlaps and makes everything unreadable. I learned the basics from another thread on here, but still struggling. I only want my name in the header. I tried to modify it like what you see below, but then I don't get anything at all. This is my YAML:
---
title: "Something"
author: "something"
date: "42 42 42"
output: pdf_document
includes:
in_header: {My name}
fontsize: 12pt
header-includes:
\usepackage{setspace}
\onehalfspacing
---
Anyone who could write it so that I get only my name at the top of the page? Also, the onehalfspacing is the same as setting spacing to 1.5 in word right?
I think there is a conceptual problem: The things you put in includes: in_header: in the yaml are the files included in the preamble of your tex document, similar to what you have in header-includes:. This is not in any way related to the headline of your document.
If you like to change this, have a look at the fancyhdr latex package
Please also note that the syntax for multiline header-includes: is wrong in your example. You need to prefix each line with -
---
title: "Something"
author: "something"
date: "42 42 42"
output: pdf_document
fontsize: 12pt
header-includes:
- \usepackage{setspace}
- \onehalfspacing
- \usepackage{fancyhdr}
- \fancyhead[c]{your name}
- \pagestyle{fancy}
- \setlength{\headheight}{15pt}
---
test
\newpage
test

How to change font in RMarkdown when using "rticles" package?

I recently installed the "rticles" package in R to automatically set up a journal article template in RMarkdown. I've been pretty impressed with it so far, but I'd like to be able to change the font. Surely this is possible somehow, but I have been unable to find any online resource explaining how to do it.
I am interested in knitting to PDF.
Here is the YAML at the top of my RMarkdown script:
---
title: This title
author:
- name: This author
email: t.author#thisPlace.com
affiliation: This institute
address:
- code: This institute
address: Street, City, State, etc.
abstract: |
This is the abstract.
It consists of two paragraphs.
keywords: "fun, happiness"
journal: "This Elsevier Journal"
date: "`r Sys.Date()`"
output: rticles::elsevier_article
---
I generated this by running the following line of code in R:
rmarkdown::draft("Test.Rmd", template = "elsevier_article", package = "rticles")
So where in all of this can I control font? Before using "rticles" I used to change the font by changing the latex engine and then specifying the font as follows:
---
title: This title
author: "This author"
date: "`r Sys.Date()`"
output:
pdf_document:
toc: yes
toc_depth: 4
fig_caption: TRUE
df_print: kable
latex_engine: xelatex
mainfont: Calibri Light
---
Is it possible to do something analogous to this in "rticles"?
The way you control fonts is analogous to what you did before:
---
title: This title
author:
- name: This author
email: t.author#thisPlace.com
affiliation: This institute
address:
- code: This institute
address: Street, City, State, etc.
abstract: |
This is the abstract.
It consists of two paragraphs.
keywords: "fun, happiness"
journal: "This Elsevier Journal"
date: "`r Sys.Date()`"
output:
rticles::elsevier_article:
latex_engine: xelatex
mainfont: Calibri Light
---

2 Logo in R Markdown on PDF

I am using below code to add a company logo in r markdown in a pdf version and
the output is fine.
I need to add 2 logo's on each page - one for my client and other for our
company.
Is is possible to add 2 logo's in a pdf using r markdown.
---
title: "Complaints Text Model"
author: "ANALYTICS TEAM"
date: '`r format(Sys.Date(), "%B %d, %Y")`'
output:
pdf_document:
toc: yes
header-includes:
- \usepackage{fancyhdr}
always_allow_html: yes
---
\addtolength{\headheight}{1.0cm}
\pagestyle{fancyplain}
\rhead{\includegraphics[height=1.2cm]{D:/D Drive Data/Shivi/R Project/my company.png}}
\renewcommand{\headrulewidth}{0pt}
One can be on one side of the page and other logo on the other side.
All you need to do is imitate your syntax for the left header:
\rhead{\includegraphics[height=1.2cm]{D:/D Drive Data/Shivi/R Project/my company.png}}
\lhead{\includegraphics[height=1.2cm]{D:/D Drive Data/Shivi/R Project/client.png}}

Resources