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.