Insert a Logo in Upper Right Corner of R Markdown PDF Document

Insert a logo in upper right corner of R markdown pdf document

Ok, I have found the solution:

---
title:
header-includes:
\usepackage{graphicx}
\usepackage{fancyhdr}
\pagestyle{fancy}
\setlength\headheight{28pt}
\fancyhead[L]{\includegraphics[width=5cm]{GPIM_Logo_300x85.png}}
\fancyfoot[LE,RO]{GPIM}
output: pdf_document
---

Include logo (image) on every page of R markdown pdf

This is a template for you:

---
title: 'You are really need to use LaTeX'
author: "You"
date: "`r Sys.Date()`"
output:
pdf_document

header-includes:
\usepackage{fancyhdr}
\usepackage{graphicx}
---

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

\addtolength{\headheight}{3.0cm}
\fancypagestyle{plain}{}
\pagestyle{fancy}
\fancyhead[R]{\includegraphics[width = 100pt]{your_pic.png}}
\renewcommand{\headrulewidth}{0pt}


This is an R Markdown document. Markdown is a simple formatting syntax for
authoring HTML, PDF, and MS Word documents. For more details on using R Markdown
see <http://rmarkdown.rstudio.com>.

and blah-blah...

Sample Image

So, don't forget to install LaTeX and packages fancyhdr, graphics.

How to do it, you can see there.
Or you can install MikTeX etc. You can find a lot of info at the SO/in the web.

The knowledge of LaTeX will save you not once a time in the future life ;)

Insert a logo in upper right corner of R markdown html document

You can use htmltools::img with a little inline CSS for positioning. src can take a path directly, but when images aren't just handled like plots, sometimes knitting fails to convert images to a URI properly, which in turn causes them to fail to render. Using self_contained: false in the YAML is a quick solution, but it's not much harder to use knitr::image_uri to manually convert the image:

---
title: "Title"
author: "Author"
output: html_document
---


```{r, echo=FALSE}
htmltools::img(src = knitr::image_uri(file.path(R.home("doc"), "html", "logo.jpg")),
alt = 'logo',
style = 'position:absolute; top:0; right:0; padding:10px;')
```

---

# 1. Header

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor.

page with logo

2 Logo in R Markdown on PDF

All you need to do is imitate your syntax for the left header:

\rhead{\includegraphics[height=1.2cm]{D:/D Drive Data/Shivi/R Project/my company.png}}
\lhead{\includegraphics[height=1.2cm]{D:/D Drive Data/Shivi/R Project/client.png}}

How to insert a logo into the footer of an R Markdown document

I simply add it as an image in the last line of code.

![](logo.png){height='25'}

Just to share, I like to add my logo at the top right corner via the YAML:

---
title: "This is My Title<img src=\"logo.png\" style =\"float: right; width:12%\"/> "
date: "06 Nov 2020"
---

Company logo in PDF output only on the first page

The \includegraphics code line is insert after the R SETUP chunk in markdown.
Here is an example of where I put the line \includegraphics :

---
geometry: "margin=1.5cm"
classoption: landscape
output:
pdf_document: # Export to pdf
number_sections: yes
includes:
in_header: ltx.sty
---



```{r SETUP, include=FALSE, message=FALSE, warning=FALSE}

knitr::opts_chunk$set(echo = FALSE,
warning = FALSE,
message = FALSE,
results = "asis")

library(knitr)
library(kableExtra)
library(some_packages)

options(scipen = 999,
digits = 2,
width = 110)

```

\definecolor{astral}{RGB}{87,146,204}
\allsectionsfont{\color{astral}}
\setcounter{tocdepth}{5}


<!-- Title page -->
\includegraphics[width=7cm]{logo.jpg}

\begin{center}\begin{Large}
Project 1
\end{Large}\end{center}

\vfill


# Some R chunk
```{r results='asis'}
# Table, code, graphics.
```

So the line is insert between the R SETUP chunk and the next R chunk.

R Markdown: Putting an image in the top right hand corner of HTML and moving title down

Option 1:

Add this script at the beginning (or somewhere else) of your RMarkdown document:

<script>
$(document).ready(function() {
$head = $('#header');
$head.prepend('<img src=\"logo.jpg\" style=\"float: right;width: 150px;\"/>')
});
</script>

This will look like

Sample Image

For the script to work, the image has to be in the same folder as the .Rmd document. You could also give the <img>tag a certain id and add more precise CSS styling with

<style>
#myLogo {
float: right;
width: 120px;
...
</style>

Option 2:

Create an extra HTML file (e.g. extLogo.html) that contains the logo like:

<div><img src="logo.jpg" width="200px" align="right"></div>

Then modify the YAML header like this:

---
title: "Test"
author: "Martin Schmelzer"
date: "13 Juli 2016"
output:
html_document:
includes:
in_header: extLogo.html
---

This looks like

Sample Image

and might need some further margin/padding options...



Related Topics



Leave a reply



Submit