Anyone a suggestion how to set the header and footer of a #quarto .qmd #rstats pdf?
I tried this, but no footer shows:
---
title: "Untitled"
format:
pdf:
include-in-header:
text:
\usepackage{fancyhdr}
---
\fancyfoot[L]{Footer text}
# Chapter ONE
text
\newpage
# Chapter TWO
Can I use fancyhdr? If yes, how? If not, what then? Thanks!
Yes, It is possible to use fancyhdr (see the answer by #Julian).
But also keep in mind that, Quarto uses KOMA-Script classes (scrartcl by default) and KOMA-Script suggests using scrlayer-scrpage latex package for handling header and footers instead of fancyhdr. See the manual chapter 05, p. 253.
---
title: "Untitled"
format:
pdf:
include-in-header:
text: |
\usepackage{scrlayer-scrpage}
\rohead{Header text}
\lofoot{Footer text}
---
# Chapter ONE
text
\newpage
# Chapter TWO
You may also want to go through this question and the corresponding answer on Tex StackExchange.
You are not that far away from the solution. If you want to use fancyhdr, this could work (note that you need to add text: | in order to have multiple lines of latex code):
---
format:
pdf:
include-in-header:
text: |
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[C]{Header text}
\fancyfoot[L]{Footer text}
---
# Chapter ONE
text
\newpage
# Chapter TWO
Related
I am preparing a Quarto presentation using beamer and would like to add the frame number at the bottom of each slide (analogous to the slide-number option in revealjs).
Could anybody tell me how I can do this?
I already figured out that the slide-number option does not exist for beamer.
Alternatively, you can control it yourself like this (see here)
---
title: "Presentation"
format:
beamer:
aspectratio: 32
navigation: horizontal
header-includes: |
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{footline}[page number]
---
# Intro
## second slide
The default theme does not include slide numbering, but you could use one with, e.g. Boadilla:
---
title: "Slide numbering in Beamer"
format:
beamer:
theme: Boadilla
editor: visual
---
I would like the RMarkdown code below (at the end of the post) to output pages with one of the header options below. The main issue is how to achieve the formatting as I know how to get the date and page numbers.
I have googled for putting tables into the header, but haven't found anything. Formatting the data more precisely is an option too (that is Header Option 2), but I haven't found anything on how to do this. I have played around with formatting but nothing worth putting here that isn't already in the RMarkdown code below.
Question: is it possible to implement one of the options below ? And how can it be done.
Header Option 1: With Table including text formatting (including the : character if possible but that is not absolutely necessary).
Header Option 2: Formatted Similarly without the Table or this can even have a box around it.
Code for Creating a Multi Page Example PDF This is the item I would like to modify the header on to include either the table solution or just the formatted solution without the table.
---
title: "R Markdown Example With Numbered Sections"
output:
bookdown::pdf_document2:
toc: true
toc_depth: 6
number_sections: true
includes:
in_header: header.tex
header-includes:
- \usepackage{fancyhdr}
- \usepackage{lastpage}
- \pagestyle{fancy}
- \fancyhead[RO,RE]{Page \thepage\ of \pageref{LastPage}}
- \fancyhead[LO,LE]{Header Message}
- \fancyfoot[LE,LO]{Footer Messge on the Left}
- \fancyfoot[LE,RO]{Footer Messge on the Right}
---
\thispagestyle{fancy}
# Example R Rarkdown : Numbered Sections
## R Markdown
### Description
Some description text
\newpage
#### Details
Details go here.
\newpage
## Plots
Plots go here
\newpage
Last page
This is one way, no doubt there are others...
Create a new fancy header page style
Define the table style header (and remove some of the default behaviours)
remove the head rule
for some reason the first page does not like a header so force the header on the first page with \thispagestyle(...)
define the subsequent page styles as the tableheader.
Edit appearance as required...
---
title: "R Markdown Example With Numbered Sections"
output:
bookdown::pdf_document2:
toc: true
toc_depth: 4
number_sections: true
header-includes:
- \usepackage{fancyhdr}
- \usepackage{lastpage}
- \usepackage{array}
- \usepackage{lipsum}
---
\fancypagestyle{tableHeader}{
\fancyhf{}
\setlength\headheight{90pt}
\fancyhead[C]{
\centering{
\begin{minipage}{1.1\textwidth}
\renewcommand{\arraystretch}{2}
\begin{tabular}{|>{\centering\arraybackslash}m{0.2\textwidth}|>{\centering\arraybackslash}m{0.2\textwidth}|>{\centering\arraybackslash}m{0.2\textwidth}|>{\centering\arraybackslash}m{0.2\textwidth}|}
\hline
\multicolumn{4}{|c|}{\textbf{\LARGE{Title}}} \\
\hline
\textbf{\Large{Field 1:}} & \textbf{\Large{Field 2:}} & \textbf{\Large{Date:}} & \textbf{\Large{Page:}}\\
\textbf{\Large{Information}} & \textbf{\Large{Information}} & \textbf{\Large{`r Sys.Date()`}} & \textbf{\Large{{\thepage} of \pageref{LastPage}}}\\
\hline
\end{tabular}
\end{minipage}
}}
}
\renewcommand{\headrulewidth}{0pt}
\thispagestyle{tableHeader}
\pagestyle{tableHeader}
# Section 1
\lipsum[3]
## sub section
\newpage
\lipsum[2]
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
In an R markdown document (html and presentations), is it possible to manually split the title onto multiple lines? I tried playing with pipes which produces orrendous output.
---
title: 'A title I want to split on two lines'
author:
date:
output:
ioslides_presentation
---
Examples for adding an abtract show the use of pipes | to break lines and include paragraphs. This works as well for the title and other yaml elements. For an abstract or title:
---
abstract: |
What works for the abstract.
Works for the title, too!
title: |
| title
| subtitle
output: pdf_document
---
For an HTML output just us the <br> tag while if your output is a PDF or PDF presentation standard LaTeX code to break line given by \\ should work.
Example
---
title: 'A title I want to <br> split on two lines'
author:
date:
output:
ioslides_presentation
---
For PDF
Just to rule out possibilities, I've tried to put \\ or \newline, both do not split, so for PDF seems to be a little bit tricky. \linebreak stop knitr parsing. Maybe another user can solve this question for knitr PDFs.
For PDF output, experimentation revealed that the following works:
---
title: 'A title I want to \nsplit on two lines'
author:
date:
output: pdf_document
---
That is two spaces followed by \n.
I am using RStudio for writing markdown documents and want to add Table of Contents (TOC) at top of the documents so that the user could click the relevant section for reading. There were some relevant examples on rpubs but now I can't seem to find them. Please note that I don't use pandoc and am quite new to Rmd & knitr. Is there any way to add TOCs without using pandoc? If using pandoc is must then which functions are relevant?
EDIT
Here's a small sample page:
---
title: "Sample Document"
output:
html_document:
toc: true
theme: united
---
Header 1
---------------
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>.
## Header 2
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)
```
### Header 3
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
I tried running this in RStudio v 0.98.864 and it worked! but sadly it didn't work on 0.98.501 and 0.98.507. I am working on my thesis in 0.98.501 and after updating RStudio, some of my analyses didn't work. So, I reverted back to 0.98.501.
What should I do now? I really want TOCs but without harming the outputs of other analyses.
The syntax is
---
title: "Sample Document"
output:
html_document:
toc: true
theme: united
---
in the documentation. Make sure this is at the beginning of your document. Also make sure your document actually has headers otherwise R can't tell what you want in the table of contents.
Syntax with more options:
---
title: "Planets"
author: "Manoj Kumar"
date: "`r format(Sys.time(), '%B %d, %Y')`"
output:
html_document:
toc: true # table of content true
toc_depth: 3 # upto three depths of headings (specified by #, ## and ###)
number_sections: true ## if you want number sections at each table header
theme: united # many options for theme, this one is my favorite.
highlight: tango # specifies the syntax highlighting style
css: my.css # you can add your custom css, should be in same folder
---
If you are using pdf_document, you might want to add table of contents in a new page, which toc: true does not allow. It puts the table of contents right after the document title, author and date--because it is in yaml.
If you want to have it in a new page, you have to use some latex language. Here is what I did.
---
title: \vspace{3.5in}"Title"
author: "Name"
date: "`r Sys.Date()`"
output:
pdf_document:
fig_caption: true
number_sections: true
---
\newpage # adds new page after title
\tableofcontents # adds table of contents
\listoffigures
\listoftables
\newpage
So, after yaml (the chunk between ---), I added a new page using \newpage, then a table of contents using \tableofcontents, a list of figures using \listoffigures, a list of tables \listoftables, and a new page before everything else.
Note, \vspace{3in} in the title adds vertical space of 3 inch from the top before printing yaml (title, etc.).
Read more here: https://www.sharelatex.com/learn/Table_of_contents