1
votes

I am trying to create an automated report in rmarkdown for business partners and I am a bit stuck on how to set up the headers using the Latex package fancyhdr.

The report includes a table of contents set to level 1 headers, but there are sub-sections in the report that are created using level 2 headers.

When I generate the PDF the fancy header has the level 1 header on the right header (which is fine), the message I set in the central header (also fine), and the sub-section (level 2 header) in the left header.

I would like to remove this, but the documentation is very vague as to how to do so - I've just spent a considerable amount of fruitless time trying to get this to work.

Here are the YAML settings at the top of the R Markdown document:

title: "Report Title"
author: "Authors"
date: 'Date'
output: 
  pdf_document:
    latex_engine: xelatex
    toc: true
    toc_depth: 1
header-includes:
  - \usepackage{fontspec}
  - \setmainfont{Gotham Book}
  - \usepackage{booktabs}
  - \usepackage[tocflat]{tocstyle}
  - \usetocstyle{standard}
  - \usepackage{fancyhdr}
  - \pagestyle{fancy}
  - \fancyhead[CO,CE]{Center Message}
  - \fancyfoot[CO,CE]{Footer Message}
  - \fancyfoot[LE,RO]{\thepage}
---
1

1 Answers

1
votes

These are the "left-odd" and "right-even" headers. If you set them to nothing using \fancyhead[LO,RE]{} they will go away:

---
title: "Report Title"
author: "Authors"
date: 'Date'
output: 
  pdf_document:
    latex_engine: xelatex
    toc: true
    toc_depth: 1
header-includes:
  - \usepackage{fontspec}
  - \usepackage{booktabs}
  - \usepackage[tocflat]{tocstyle}
  - \usetocstyle{standard}
  - \usepackage{fancyhdr}
  - \pagestyle{fancy}
  - \fancyhead[CO,CE]{Center Message}
  - \fancyfoot[CO,CE]{Footer Message}
  - \fancyfoot[LE,RO]{\thepage}
  - \fancyhead[LO,RE]{}
  - \usepackage{blindtext}
---

\blinddocument

(I have removed your font and inserted some sample text to show the effect.)