How to edit footer in RMarkdown using the fancyhdr package

Viewed 790

I have created a PDF in RMarkdown with the fancyhdr package in LaTeX. I'm trying to find a solution in which I can insert a horizontal line as a footer (just above the page number), as well as the page number in the right hand corner similar to the image I have attached. Additionally, is there a way in which I can change the color of all the hyperlinks (such as the table of contents) from the default black color to the same color as in the image?

My YAML is as follows

---
title: "Template for a Dynamic Report for Work"
Uni_Logo: Tex/logo.jpg
Author1: "Tangeni Shatiwa" 
# ----- Manage headers and footers:
#BottomLFooter: $Title$
#BottomCFooter:
#TopLHeader: \leftmark # Adds section name at topleft. Remove comment to add it.
BottomRFooter: "\\footnotesize Page \\thepage" # Add a '#' before this line to remove footer.
addtoprule: TRUE
addfootrule: TRUE               # Use if footers added. Add '#' to remove line.
toc: TRUE
numbersections: TRUE             # Should sections (and thus figures and tables) be numbered?
fontsize: 11pt                  # Set fontsize
linestretch: 1.2                # Set distance between lines.
link-citations: TRUE   # This creates dynamic links to the papers in reference list.
linkcolor: blue
output:
  pdf_document:
    includes:
      in_header: "header.tex"
---

and the contents of the header.tex file are as follows

\usepackage{fancyhdr}
\usepackage{titling}
\pagestyle{fancy}
\fancyhead{}
\fancyfoot{}
\setlength{\headheight}{50pt}
\lhead{\includegraphics[width = .2\textwidth]{logo.jpg}}
\fancyfoot[R]{\thepage}
\renewcommand{\footrulewidth}{0pt}

\pretitle{%
  \begin{center}
  \LARGE
  \includegraphics[width=4cm,height=6cm]{logo.jpg}\\[\bigskipamount]
}
\posttitle{\end{center}}

TIA! enter image description here

1 Answers

Here's an example rmarkdown document and header.tex file. I removed the logo lines in header.tex since I don't have your logo. Let me know if this is what you had in mind.

rmarkdown file

---
title: "Template for a Dynamic Report for Work"
Author1: "Tangeni Shatiwa" 
BottomRFooter: "\\footnotesize Page \\thepage" # Add a '#' before this line to remove footer.
addtoprule: TRUE
addfootrule: TRUE               # Use if footers added. Add '#' to remove line.
toc: TRUE
numbersections: TRUE             # Should sections (and thus figures and tables) be numbered?
fontsize: 11pt                  # Set fontsize
linestretch: 1.2                # Set distance between lines.
link-citations: TRUE   # This creates dynamic links to the papers in reference list.
urlcolor: darkred
output:
  pdf_document:
    includes:
      in_header: "header.tex"
---

\newpage
\pagenumbering{arabic} 

Some text

[This is a link to Stack Overflow](www.stackoverflow.com)

Some more text

\newpage

Even more text
---

\newpage
\pagenumbering{arabic} 

Some text

[This is a link to Stack Overflow](www.stackoverflow.com)

Some more text

\newpage

Even more text

header.tex file

\usepackage{fancyhdr}
\usepackage{titling}
\pagestyle{fancy}
\fancyhead{}
\fancyfoot[L]{This is the left footer}
\fancyfoot[R]{\thepage}
\fancyfoot[C]{}
\setlength{\headheight}{50pt}
%\lhead{\includegraphics[width = .2\textwidth]{logo.jpg}}
\renewcommand{\footrulewidth}{1pt}
\pretitle{%
  \begin{center}
  \LARGE
  %\includegraphics[width=4cm,height=6cm]{logo.jpg}\\[\bigskipamount]
}
\posttitle{\end{center}}
\pagenumbering{gobble}
\usepackage{xcolor}
\definecolor{darkred}{rgb}{0.7,0,0}

PDF output

enter image description here

enter image description here

Related