2

I was wondering if there is a way to include the company logo to a PDF document created by R Markdown only on the first page of the document. I have searched for an answer and the closest I could find is this. There are multiple solutions presented in the answers, however, neither of them works for me because they either:

  • include the logo at every page of the document (not just first); or
  • include the chapter title in the header (and a horizontal line below it) along with the logo.

I am looking for a way to include just the plain logo, with no chapter titles only on the first page of a PDF R Markdown document and I've ran out of all the resources I could find online. Is there someone who could aid me?

Before anyone asks: yes, it strictly has to be a PDF document, not HTML.

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
J. Doe
  • 1,544
  • 1
  • 11
  • 26
  • I do it by using : ``\includegraphics[width=7cm]{yourCOMPANYlogo.jpg}`` You can adjust the width value. To use this you have to use R Markdown and Latex tho. – Gainz May 27 '19 at 14:25
  • Is this something I would put in the YAML, or below where the regular text is? – J. Doe May 27 '19 at 15:05
  • I will post you a more complete example as an answer since I can't post long code in comment. – Gainz May 27 '19 at 15:10

1 Answers1

2

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.

Gainz
  • 1,721
  • 9
  • 24
  • On a second note, though, if my Markdown doc includes the title, author and date of the document, is there a way to have the logo appear in the header above the title and other fields? – J. Doe May 29 '19 at 09:44
  • 1
    I am quite not sure how I would do it but I will take a look. If I find something I'm gonna tag you here @J.Doe and update my answer. – Gainz May 29 '19 at 14:12