0

I am new to coding and Latex so please forgive me as I'm sure this is a very straight forward solution. I am creating a PDF report using RMarkdown with a .tex file to control the header, margins, and page type.

I have managed to create a base header that I will continue to tweak more to my liking but I need to be able to turn the header off for the 2nd page of the report and then turn it back on for the 3rd page. I have a flextable that is too large with the header to fit on the 2nd page but fits without it.

I have read many questions where they are asking about the 1st page but I haven't been able to tweak those answers to solve my problem. I have read the fancyhdr vignette and I'm sure the answer is in there but everything I tried did not work. Most turned the header off on the first page and didn't touch the second. Do I need to put the code directly into the .rmd?

YAML header for my RMarkdown file:

---
title: "Team Report"
classoption: landscape
output:
  pdf_document:
    includes:
      in_header: "preamble.tex"

---

preamble.tex file

\usepackage{fancyhdr}
\usepackage{etoolbox}
\usepackage{color}
\usepackage{geometry}

 \geometry{a4paper, landscape, left = 13mm, right = 5mm, top = 5mm, bottom = 13mm, head = 44pt, includeheadfoot}
  \headsep = 2mm



\AtBeginDocument{\let\maketitle\relax}
\pagestyle{fancyplain}
\definecolor{col1}{RGB}{210, 35, 42}
\fancyhead[L]{\colorbox{col1}{{\color{white}{\large\textbf{July 2020}}}}}
\fancyhead[CO,CE]{\Huge\textbf{Team Report Template}}
\rhead{\includegraphics[height=1.2cm]{Team_logo.png}} % right logo
\renewcommand{\headrulewidth}{4pt}

3
  • your code does not compile – js bibra Jul 20 '20 at 0:47
  • \newpage\thispagestyle{empty} just before the R chunk making the second page should work. – Fran Jul 20 '20 at 11:07
  • Ah this worked! My problem was I was trying to put that command within my .tex file instead of putting it directly into the .Rmd file. Thank you! – VickiB Jul 21 '20 at 18:09
0

R markdown can use LaTeX commands directly, so simply add \thispagestyle{empty} in the second page.

The command just before or after the R chunk could be enough, but to be sure will be not load before the first page break nor after the second page break, place it just before a \newpage: I

---
title: "Team Report"
classoption: landscape
output:
  pdf_document:
    includes:
      in_header: "preamble.tex"

---

(first page contents)

\newpage 
\thispagestyle{empty}


 
```{r}
# R chunk of the second page 
```

Alternatively, you can also load the afterpage package and place \afterpage{\thispagestyle{empty}} somewhere in the first page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.