Marc BF
Marc BF

Reputation: 119

My footer disappears after the first page (but not the header!) in R-Markdown

I have a footer and header set by using the fancyhdr package in a R-Markdown generated PDF. However, at some point I notcied my footer disappears after the first page, while my header appears in each page as intended. I have no idea why can it be, I tried lots of stuff but nothing seemed to work so far.

header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyfoot{}
- \fancyhead{}
- \renewcommand{\headrulewidth}{0pt}

... (some chunks of code go here)

\fancyhead[L]{\includegraphics[width=4cm]{/Users/username/Documents/SP_logo_login.png}}
\fancyfoot[R]{Page \thepage\ of \pageref{LastPage} \\ \today , \currenttime}
\fancyfoot[L]{Identification Report \\ User generating the report: {`r paste(user_code)`}}

\vspace*{1\baselineskip}

# IDENTIFICATION REPORT

(some more LaTex and code chunks follow, including bar plots and KableExtra tables)

...

It does not matter wether I put the fancyfoot after some code or right under header-includes. The result is the same. The footer is correctly generated on the first page, but that's all, while the header appears at the beginning of every page.

Any idea on what could be going on?

Upvotes: 0

Views: 2620

Answers (1)

Your headline is much higher than the default \headheight and therefore pushes the content and the footline off the page. There is an explicit warning in the .log which tells you how height the headline needs to be. The exact value will depend on the aspect ration of your image, for the example image I used, it is about 75pt

---
output:
  pdf_document:
    keep_tex: true

header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyfoot{}
- \fancyhead{}
- \renewcommand{\headrulewidth}{0pt}    
- \geometry{head=75pt, includehead=true, includefoot=true}

---

... (some chunks of code go here)

\fancyhead[L]{\includegraphics[width=4cm]{example-image-duck}}
\fancyfoot[R]{Page \thepage\ of \pageref{LastPage} \\ \today}
\fancyfoot[L]{Identification Report \\ User generating the report: }

\vspace*{1\baselineskip}

# IDENTIFICATION REPORT

(some more LaTex and code chunks follow, including bar plots and KableExtra tables)

...

Upvotes: 1

Related Questions