Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
703 views
in Technique[技术] by (71.8m points)

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

I would like to put a company logo image in the top right hand side of my R markdown report, and then move the title down, say 3 or 4 cm lower than the default position. The idea being that it looks like company letterhead.

Could anyone suggest how I could code this in my .Rmd file?

Thanks for any help!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

enter image description here

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

enter image description here

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...