Modify position of fancyhdr footer in R markdown - r

I have been searching to solve this issue for quite some time, but I cannot get it right. I use R markdown for creating a beamer presentation and I would like to include a footer by using the fancyhdr LaTeX package. The problem that I encounter is that the footer is not completely on each slide. I assume that it has to do something with the margins used by beamer, but I do not know how to change this.
Here is a MWE. This is the .rmd file:
---
title: "Untitled"
author: ""
date: "10 januari 2019"
output:
beamer_presentation:
includes:
in_header: preamble.tex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## R Markdown
SOME NICE TEXT
This is in the file "preamble.tex" that is specified in the YAML:
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{}
\chead{}
\rhead{}
\lfoot{Text in footer}
\cfoot{}
\rfoot{\thepage}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
This is how it looks. The footer is not entirely on the slide:
Thank you in advance for your help!

When using beamer, it's much more natural to set the footline template than try to use fancyhdr like you'd use with, for example, and article class document (or a pdf_document in R Markdown world). Changing your preamble.tex to the following:
\setbeamertemplate{footline}
{
\leavevmode%
\hbox{%
\begin{beamercolorbox}[wd = .5\paperwidth, ht = 1ex, dp = 1ex, center]{author in head/foot}%
Text in footer
\end{beamercolorbox}%
\begin{beamercolorbox}[wd = .5\paperwidth, ht = 1ex, dp = 1ex, center]{date in head/foot}%
\insertframenumber{}
\end{beamercolorbox}
}%
\vskip3pt%
}
\addtobeamertemplate{footline}{\begin{center}\rule{0.6\paperwidth}{0.4pt}\end{center}\vspace*{-1ex}}{}
results in this output:
which I believe is pretty close to what you want (the black bar there in the middle is just space between the slides in the PDF viewer I was using); you can tweak the footline definition until you get it precisely there.

Related

Change font and color for figure captions in Rmarkdown in PDF output

I'm wondering how to change font and color specifically for figure captions in Rmarkdown for a PDF output. I know how to do this for word output (creating a separate document), but often figures are submitted to journals as PDFs.
Note that this is not whether you can change the color of text in a PDF which is answered here: Changing the font size of figure captions in RMarkdown pdf output. If I try this within the fig.cap = "fig text here.\\label{...}" I get the following error:
! Undefined control sequence.
<recently read> \cellcolor
This probably comes closest: Changing the font size of figure captions in RMarkdown pdf output, but I went to CTAN and downloaded the package and am not sure whether I have to find my R libraries and drag it to there, or what. Perhaps this is the only/easiest solution, if so, can you advise on how I should proceed with the downloaded package. Haven't done a lot in latex, so it would probably be finding how colors are defined in latex as well?
Thanks much!
James
Here is my header:
output:
pdf_document:
keep_tex: true
html_document: default
header-includes:
\usepackage{placeins}
---
You could try this:
---
title: "Untitled"
author: "bttomio"
date: "6/13/2021"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r pressure, echo=FALSE, fig.cap="\\textcolor{red}{This is red} and \\textcolor{blue}{this is blue}"}
plot(pressure)
```
-output

R Markdown: Creating Backgrounds for Powerpoints

I'm using R markdown to create a presentation, and I would really like to add a custom background on my opening slide and second slide. Currently, I have my potential themes on a separate PowerPoint document. Is there any way to add backgrounds like that?
Thanks!
To add a custom background, one can create a powerpoint template, e.g. my-styles.pptx where the background image is placed at the slide master.
Then create an Rmarkdown file like follows and place it in the same folder:
---
title: "Fancy Slides"
author: "Creative Author"
date: "2021-06-09"
output:
powerpoint_presentation:
reference_doc: my-styles.pptx
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Slide with Bullets
- Bullet 1
- Bullet 2
- Bullet 3
## Slide with R Output
```{r cars, echo = TRUE}
summary(cars)
```
More about this can be found in Yihui Xie et al. (2021) R Markdown: The Definitive Guide, Section 4.4.
Tested with RStudio Version 1.4.1714 and Powerpoint 2016.

How to remove compact title from R markdown to latex conversion?

I wrote my own titlepage and it is loaded via an include in the R-markdown file. However, this conflicts with the pandoc title. I am trying to find settings in the R markdown yaml header such that pandoc does not insert the following code snipped into the tex-file.
% Create subtitle command for use in maketitle
\newcommand{\subtitle}[1]{
\posttitle{
\begin{center}\large#1\end{center}
}
}
\setlength{\droptitle}{-2em}
\title{}
\pretitle{\vspace{\droptitle}}
\posttitle{}
\author{}
\preauthor{}\postauthor{}
\date{}
\predate{}\postdate{}
There is no clear indication in the pandoc documents or the r markdown guidelines how to disable the title generation. Any help would be appreciated.
Update: In particular, I am looking for solutions that allow me to keep creating my title page with the \maketitle command. That is why I focussed on this particular code snipped that I want to get rid of.
I also use my own title page with rmarkdown documents for latex/pdf outputs. To remove the title, you can add the following command in a text file called with in_header :
\AtBeginDocument{\let\maketitle\relax}
A reproductible example with the header.tex file built directly within the Rmd document:
---
title: "RMarkdown No title Test"
author: "StatnMap"
date: "July 30, 2017"
output:
pdf_document:
includes:
in_header: header.tex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r rm_title_page, echo=FALSE}
head <- cat('
\\AtBeginDocument{\\let\\maketitle\\relax}
', file = "header.tex")
```
# Title 1
**Some text**
# Title 2
**Some text**
Using compact-title: false in the YAML works.
---
title: "This title is not compact"
author: "Test"
date: "2019 May 10"
output: pdf_document
compact-title: false
---
I had the same problem today. Here's what I did. (Maybe I'll update the solution when I come up with something better.)
The solution is dumb but useful. I can't set an arbitrary space between the lines now, because I used \newline.
---
title: "\\huge My Smart Title"
author: "\\newline \\Large My Smart Author"
date: "\\newline \\Large 2018-12-25"
output:
pdf_document:
includes:
in_header: preamble.tex
latex_engine: xelatex
---
Below are the outputs before and after the solution.
BEFORE:
AFTER:
Note:
You may be confused about the different sizes of the "author" and the "date" in the two pictures above, if you don't know that the fontsize of the "author" and the "date" is \large instead of \Large by default.
END

Add special beamer slide using RMarkdown

I want to produce a beamer presentation from a RMarkdown file.
I am in this case using this beautiful template: https://github.com/matze/mtheme
How in markdown can you specify that you want to insert, not a "normal" slide, by a special one, such as an appendix slide, or a standout slide?
This template contains a standout slide that I would like to use as final slide as they do in their demo slides (http://mirrors.standaloneinstaller.com/ctan/macros/latex/contrib/beamer-contrib/themes/metropolis/demo/demo.pdf)
In beamer, I would do:
\begin{frame}[standout]
Questions?
\end{frame}
What is the equivalent in Markdown?
Setting frame options is pretty straight forward:
---
title: "Untitled"
output: beamer_presentation
theme: "metropolis"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## {.standout}
Questions?

add image in title page of rmarkdown pdf

I am attempting to create an rmarkdown document. I have finally figured out a way to approach this, although it has taken quite some time. The last thing I would like to be able to do is to add an image to the title page of my pdf document.
The trouble I have is that my title page is defined by the top section of YAML. Below is the contents of my example.Rmd file. I use the Knit PDF button in RStudio to turn it into a PDF.
---
title: "This is a my document"
author: "Prepared by: Dan Wilson"
date: '`r paste("Date:",Sys.Date())`'
mainfont: Roboto Light
fontsize: 12pt
documentclass: report
output:
pdf_document:
latex_engine: xelatex
highlight: tango
---
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r}
summary(cars)
```
You can also embed plots, for example:
```{r, echo=FALSE}
plot(cars)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
If anyone has some tips that would allow me to put an image (logo.png) above my title that would be great.
Based on the previous solution, the following code does not require an auxiliary header.tex file. All contents are contained in the .Rmd file. The LaTeX commands are instead defined in a header-includes block in the YAML header. More info can be found here.
Replace my_graphic.png below with your local graphic file.
---
title: "A title page image should be above me"
header-includes:
- \usepackage{titling}
- \pretitle{\begin{center}\LARGE\includegraphics[width=12cm]{my_graphic.png}\\[\bigskipamount]}
- \posttitle{\end{center}}
output:
pdf_document:
toc: true
---
\newpage
# Section 1
Some text.
I was able to solve this using LaTeX package titling
---
title: "Untitled"
author: "Name"
date: "September 19, 2015"
output:
pdf_document:
includes:
in_header: header.tex
---
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r}
summary(cars)
```
You can also embed plots, for example:
```{r, echo=FALSE}
plot(cars)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
Where the header.tex should include the following code:
\usepackage{titling}
\pretitle{%
\begin{center}
\LARGE
\includegraphics[width=4cm,height=6cm]{logo.png}\\[\bigskipamount]
}
\posttitle{\end{center}}
and replace logo.png with the image you would like to use and make sure the file is in the root directory of your Rmd file. You can change image width and height to your needs. For more information on available options go to titling
For a beamer presentation you can do it like this:
title: "Title"
subtitle: "Subtitle"
author: "author"
date: "date"
header-includes:
- \titlegraphic{\centering \includegraphics[width=12cm]{titlepic.png}}
output:
beamer_presentation:
latex_engine: xelatex
theme: "metropolis"
highlight: "espresso"
classoption: "aspectratio=169"
The titlegraphic will be placed below your title text
For beamer presentation if you want an image at the bottom you can kind of cheat and add the image where the date line should be. Then if you want to insert date you can add institution (which is before date). the ![] should be tabbed (4 spaces from the far left of the page)
date: |
![](mypathtofile/myimage.png){width=3in}

Resources