how to make background color for footer in rmarkdown using Latex?

Viewed 715

I want to add background color to my footer as shown below. enter image description here

I'm not getting background color i added to my footer but it didn't work. below code only generates footer. how to get output as shown above making backgroundcolor

---
title: "123"
output:
  pdf_document: 
    keep_tex: true
classoption: svgnames
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyhead{}
- \fancyfoot{} 
- \lfoot[LE,LO]{ABCDEFGHIJ 2020 1.3.4}
- \fancypagestyle{plain}{\pagestyle{fancy}}

---
2 Answers

A quick way to add a coloured box the footer with tikz:

\documentclass{article}

\usepackage{xcolor}
\usepackage{tikz}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{}
\fancyfoot{} 
\lfoot[LE,LO]{\tikz{\node[white,outer sep=0pt,inner sep=10pt,fill=blue!70,text width=\dimexpr\textwidth-20pt\relax,align=left] at (0,0) {ABCDEFGHIJ 2020 1.3.4};}}
\setlength{\footskip}{30.44pt}
\fancypagestyle{plain}{\pagestyle{fancy}}

\begin{document}

text

\end{document}

or in rmarkdown:

---
title: "123"
output:
  pdf_document: 
    keep_tex: true
classoption: svgnames
header-includes:
- \usepackage{tikz}
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyhead{}
- \fancyfoot{} 
- \lfoot[LE,LO]{\tikz{\node[white,outer sep=0pt,inner sep=10pt,fill=blue!70,text width=\dimexpr\textwidth-20pt\relax,align=left] at (0,0) {ABCDEFGHIJ 2020 1.3.4};}}
- \setlength{\footskip}{30.44pt}
- \fancypagestyle{plain}{\pagestyle{fancy}}
---

test

enter image description here

(The advantage of using tikz for this job is that adjusting the padding around the text gets really easy)

You could use LaTeX code. Here is an example:

---
title: "Untitled"
author: "bttomio"
date: "5/1/2021"
output: pdf_document
header-includes:
  - \usepackage{xcolor}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

This is an example^[\textcolor{white}{\colorbox{blue}{Example in a R Markdown document.}}]

-output

enter image description here

Related