Method 1:
To add a logo in your RMarkdown document, insert the script below at the beginning or somewhere else:
<script>
$(document).ready(function() {
$head = $('#header');
$head.prepend('<img src=\"logo.jpg\" style=\"float: right;width: 150px;\"/>')
});
</script>
This will display as shown here:
https://i.sstatic.net/jkRIgu.png
In order for the script to function properly, make sure the image is in the same folder as the .Rmd file. You can also assign an id
to the <img>
tag and apply specific CSS styling using
<style>
#myLogo {
float: right;
width: 120px;
...
</style>
Method 2:
If you prefer, create a separate HTML file (e.g. extLogo.html) containing the logo like this:
<div><img src="logo.jpg" width="200px" align="right"></div>
Then adjust the YAML header as follows:
---
title: "Sample"
author: "John Doe"
date: "25 August 2020"
output:
html_document:
includes:
in_header: extLogo.html
---
It will appear similar to this design:
https://i.sstatic.net/qmTYlj.png
You may need to fine-tune margin/padding settings as needed...