0

I am trying to include my company logo in an R markdown report. The output has to be pdf. The logo has to be used as a template on every page of the report in the top left of the file. Just for example, you can use this google logo https://en.wikipedia.org/wiki/Google#/media/File:Google_2015_logo.svg

I want the report to look like this (sorry for the blurry image but I just wanted to give an example) -

enter image description here

The google logo on top left should be present on every page.

I have done searches but all the searches that I have done are showing how to do this using latex or HTML output.

https://bookdown.org/yihui/rmarkdown-cookbook/latex-logo.html

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

2 Logo in R Markdown on PDF

add image in title page of rmarkdown pdf

The closest I have came is with this markdown document that is called reports.Rmd which looks like -

---
title: "Report"
output: pdf_document
params: 
  study: NA
  mid : NA
---

![Caption.](google.png)

```{r, echo=FALSE}
paste0("Study : ", params$study)
paste0("ID",  params$mid)
```

and I run this from another R script as -

library(rmarkdown)
study <- 'ABC'
mid <- '73023'

rmarkdown::render('reports.Rmd', pdf_document(), params = list(
  study = study, mid = mid
))

This runs and produce this output

enter image description here

I'll be able to resize the image with How to set size for local image using knitr for markdown? but I don't know how to place this on top left of the page. Thank you for reading.

user16024709
  • 151
  • 1
  • 12
  • Why do you not want to use latex or html solutions? – manro Oct 14 '21 at 07:59
  • This company report has to be a PDF document, I cannot share HTML files. As far as latex is concerned I haven't used it before and don't know what changes I need to do in my markdown file. – user16024709 Oct 14 '21 at 08:03
  • Bro, you really should use LaTeX solution with the case of PDF-document. I prepared to you a template. Wait a moment. – manro Oct 14 '21 at 09:51
  • If i helped to you, can you accept my answer (put a tick). Big thx ;) – manro Oct 14 '21 at 10:13
  • You can create an HTML document from Rmarkdown, and then *Print* the file to PDF from the web browser to retain HTML elements when created, and then send the PDF to whoever, it's a simple trick to keep in mind for future projects – Daniel_j_iii Oct 14 '21 at 16:02
  • @DanielJachetta Yes, you are right. And we can to make it more easier: ```"Knit to Html" - > "Open in Browser" -> right click + "Save as PDF..."``` But TeX-style will be lost. All depends on the requirements. – manro Oct 14 '21 at 16:17

1 Answers1

5

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...

enter image description here

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 ;)

manro
  • 3,529
  • 2
  • 9
  • 22
  • Also, if the OP is unaccustomed to LaTeX commands, there's LyX which uses LaTeX. Check that out: [LyX](https://www.lyx.org/)... – DeBARtha Oct 14 '21 at 10:14
  • Hi @manro, do you have any idea how to rotate a page ? I have asked a question here https://stackoverflow.com/questions/69693683/rotate-table-pdf-output-from-markdown – user16024709 Oct 25 '21 at 02:04
  • @user16024709 I'll try to find a solution ;) – manro Oct 25 '21 at 15:05