1

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 Answer 1

1

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.)

Sign up to request clarification or add additional context in comments.

1 Comment

That works perfectly, so I've marked this as a correct answer. Herzlichen Dank!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.