Creating a footer for every page (including first!) using R markdown - latex

I'd like to add to the question Creating a footer for every page using R markdown: how do I do this for the first page of the document in addition to all the following pages?
In RStudio, this code:
---
title: "Test"
author: "Author Name"
header-includes:
- \usepackage{fancyhdr}
- \usepackage{lipsum}
- \pagestyle{fancy}
- \fancyhead[CO,CE]{This is fancy header}
- \fancyfoot[CO,CE]{And this is a fancy footer}
- \fancyfoot[LE,RO]{\thepage}
output: pdf_document
---
\lipsum[1-30]
Produces this at the bottom of pg1:
and this (oddly, shouldn't this go on the left because of the \fancyfoot[LE,RO]{\thepage}?) at the bottom of pg2:
and this at the bottom of pg3:

Use
---
title: "Test"
author: "Author Name"
header-includes:
- \usepackage{fancyhdr}
- \usepackage{lipsum}
- \pagestyle{fancy}
- \fancyhead[CO,CE]{This is fancy header}
- \fancyfoot[CO,CE]{And this is a fancy footer}
- \fancyfoot[LE,RO]{\thepage}
- \fancypagestyle{plain}{\pagestyle{fancy}}
output: pdf_document
---
\lipsum[1-30]
which should override the plain page style - used on the first page with an issue of \maketitle - to be equivalent to fancy.
Remark that \fancypagestyle{plain}{} has the same effect as \fancypagestyle{plain}{\pagestyle{fancy}}.

Related

R Markdown Colored Background

I have reproduced a simple example of an R Markdown presentation. Basically, I want to achieve a colored page that overlays both the headline and the footline. At the moment, only the headline is overlayed. The approach with a preamble in a tex file is needed in my full example. "Red.jpg" is simply a red image. There may be a better approach to achieve this. The reproducible code is as follows:
---
title: "Untitled"
author: "Author"
date: "21 6 2021"
output:
beamer_presentation:
includes:
in_header: preamble.tex
---
---
\begin{tikzpicture}[remember picture,overlay]
\node at (current page.center) {\includegraphics[width=\paperwidth]{red.jpg}};
\end{tikzpicture}
The code for the preamble is as follows:
\usepackage{tikz}
\setbeamertemplate{headline}{My Title}
\setbeamertemplate{footline}{Author \hfill \insertframenumber}
This really represents a simple MWE, without borthering about spacing of footline etc.
The current result is as follows:
You can use a plain frame without head- or footline:
---
title: "Untitled"
author: "Author"
date: "21 6 2021"
output:
beamer_presentation
header-includes:
- \usepackage{tikz}
- \setbeamertemplate{headline}{My Title}
- \setbeamertemplate{footline}{Author \hfill \insertframenumber}
---
---
# {.plain}
\begin{tikzpicture}[remember picture,overlay]
\fill[red] (current page.south west) rectangle (current page.north east);
\end{tikzpicture}

Remove Chapter title from header on all pages, latex book class

Edited to include a reproducible example.
So, I've found a number of people asking about how to add the chapter title from the header of subsequent pages but I need the opposite. I'm using fancy header but need everything except the page number removed from the header (the page needs to be at the top right of every page). The code I'm using removes the header from the first page of each chapter, but every subsequent page has the chapter name in the header on the left. I'm using \documentclass[12pt,oneside]{book}.
Below is the header code:
\documentclass[12pt,oneside]{book}
\usepackage{fancyhdr} % Permits header customization. See header section below.
\fancypagestyle{plain}{
\lhead{}
\fancyhead[R]{\thepage}
\fancyhead[L]{}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot{}
}
\begin{document}
\chapter{Starting Here}
Some stuff
\newpage
New stuff
\end{document}
I have to submit this document with specific formatting requirements and want to continue using the fancyhdr package. Any help is much appreciated.
While your MWE loads the fancyhdr package, you don't actually use it for normal pages as there is no \pagestyle{fancy} or similar. This means your code only customises plain pages like they are used for the first page of a chapter.
If you want to customise normal pages as well:
\documentclass[12pt,oneside]{book}
\usepackage{fancyhdr} % Permits header customization. See header section below.
\fancypagestyle{plain}{
\lhead{}
\fancyhead[R]{\thepage}
\fancyhead[L]{}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot{}
}
\pagestyle{fancy}
\fancyhead[R]{\thepage}
\fancyhead[L]{}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot{}
\begin{document}
\chapter{Starting Here}
Some stuff
\newpage
New stuff
\end{document}
from the .cls file, I commented \pagestyle and added following code before /begin{document}.
\usepackage{fancyhdr} % Permits header customization. See header section below.
\fancypagestyle{plain}{
\lhead{}
\fancyhead[R]{\thepage}
\fancyhead[L]{}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot{}
}
\pagestyle{fancy}
\fancyhead[R]{\thepage}
\fancyhead[L]{}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot{}

How to have multiple note page in Rmarkdown beamer presentation

In Markdown beamer presentation output, my multiple notes pages are being combined into one note page. When I looked into the .tex file (from my keep_text=TRUE option), it is because the notes commands are put between \begin{frame} ... \end{frame} instead of outside \end{frame}. Below is my reproducible code in Rmarkdown beamer presentation document. Any help will be appreciated.
---
output:
beamer_presentation
keep_tex: yes
---
## slide title
- item 1
- item 2
\note{
long paragraph 1
}
\note{
long paragraph 2
}
I get this output
But what I wanted was:
You can temporarily switch from markdown to real latex and end the frame before adding the notes:
---
output:
beamer_presentation:
keep_tex: true
header-includes:
- \setbeameroption{show notes}
---
## slide title
- item 1
- item 2
``` {=latex}
\end{frame}
\note{
long paragraph 1
}
\note{
long paragraph 2
}
\begin{frame}
```
normal slide
https://rstudio.cloud/project/1051204

Page 1 shows just a number where the rest show 'Page x of 4'

The first page shows ust a centralised number, and the rest shows 'Page x of 4' with x being their respected page numbers. I want the first page to also be of this format, bu can't figure out why it's doing this
\lfoot{} % Define left footer
\rfoot{Page \thepage \hspace{1pt} of \pageref{LastPage}}
\cfoot{}
Your first page probably uses a different page style, for example empty or plain. You can also adjust this style:
\documentclass{article}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{lipsum}
\pagestyle{fancy}
\lfoot{} % Define left footer
\rfoot{Page \thepage \hspace{1pt} of \pageref{LastPage}}
\cfoot{}
\author{names}
\title{text}
\fancypagestyle{plain}{
\lfoot{} % Define left footer
\rfoot{Page \thepage \hspace{1pt} of \pageref{LastPage}}
\cfoot{}
}
\begin{document}
\maketitle
\lipsum
\end{document}

Pandoc LaTex PDF headed and footer

I am using pandoc v 1.18 I want to add header as well as footer text.
I want complete control meaning I want to place heater text at left, center and middle and the same with footer.
But I am unable to get even a single place to show up.
I have the following in my YAML header in my markdown file
---
header: This is fancy
footer: So is this
headertext: This is fancy
footertext: So is this
#abstract: This is a pandoc test . . .
documentclass: report
output:
pdf_document:
fontsize: 12pt
mainfont: Roboto
geometry: [top=2cm, bottom=1.5cm, left=1cm, right=1cm]
css : pandoc.css
linkcolor : cyan
toc : true
---
I have tried to use header and headertext separately as well and that did not work as well.
Easiest solution is to add a custom latex header. Create header.tex in your working directory and add something like:
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\rhead{Fancy on the right}
\lhead{Fancy on the left}
\cfoot{Fancy in the footer}
See the fancyhdr manual for help.
And then compile with pandoc myfile.md -o myfile.pdf -H header.tex. With Rmarkdown, this can be set in the YAML front matter:
---
output:
pdf_document:
includes:
in-header: header.tex
---
To be able to set the header with a variable in the YAML like you wanted, you will need to play with the rmarkdown latex template (see the pandoc manual section about templates) but you'll probably lose the possibility to fine-tune the header and footer with fancyhdr.

Resources