Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

I am getting started with R markdown and I would like to create a new report having our company image logo.png in the upper right corner of each page.

Is there a way to code this in the YAML section or need this to be done in a R chunk section?

like image 878
Daniel_D Avatar asked Jan 16 '15 10:01

Daniel_D


People also ask

How do I embed a PNG in R Markdown?

To add an image in markdown you must stop text editing, and you do this with the command [Alt text] precedeed by a ! Then you have to add the path to the image in brackets. The path to the image is the path from your directory to the image.

How do I create a PDF in R Markdown?

To transform your markdown file into an HTML, PDF, or Word document, click the “Knit” icon that appears above your file in the scripts editor. A drop down menu will let you select the type of output that you want. When you click the button, rmarkdown will duplicate your text in the new file format.

How do you insert a line break in R Markdown PDF?

To break a line in R Markdown and have it appear in your output, use two trailing spaces and then hit return .


1 Answers

You can use the includes option in the yaml to specify a custom addition to your latex header. The yaml part would look like

--- output:      pdf_document:       keep_tex: true       includes:           in_header: header.tex --- 

and you need to save a separate file called header.tex with the following defining your company logo like so:

\usepackage{fancyhdr} \pagestyle{fancy} \rhead{\includegraphics[width = .05\textwidth]{logo.png}} 

Here I used the fancyhdr latex package to add the logo, but there are other potential solutions. See here for more options.

like image 136
tmpname12345 Avatar answered Sep 27 '22 17:09

tmpname12345