6.3 Add logo to title page

We can use the titling LaTeX package to alter our title block to include an image. Below is a full example that shows how to add the R logo (logo.jpg) to the title page. The image can be of any format that LaTeX supports (e.g., jpg, png, or pdf).

  1. ---
  2. title: Adding a Logo to LaTeX Title
  3. author: Michael Harper
  4. date: December 7th, 2018
  5. output: pdf_document
  6. header-includes:
  7. - \usepackage{titling}
  8. - \pretitle{\begin{center}
  9. \includegraphics[width=2in,height=2in]{logo.jpg}\LARGE\\}
  10. - \posttitle{\end{center}}
  11. ---
  12. <!-- Optionally include a page break. This will force the start
  13. of the document to the second page -->
  14. \newpage
  15. This is your report.
  16. ```{r, include=FALSE}
  17. # copy the R logo to the current directory
  18. file.copy(file.path(R.home("doc"), "html", "logo.jpg"), '.')
  19. ```

An example output is shown in Figure 6.1.

A logo on a LaTeX title page.

FIGURE 6.1: A logo on a LaTeX title page.

An alternative method that does not require a special LaTeX package (titling) is to just insert the image in the title field using the Markdown syntax. For example:

  1. title: |
  2. ![](logo.jpg){width=1in}
  3. Adding a Logo to LaTeX Title

In this case, you will not need the header-includes field in the YAML frontmatter in the first example. Please note that although you cannot see them, there are two trailing spaces after ![](logo.jpg){width=1in}, which means a line break in Markdown (see Section 4.12). Without the line break, the image and the title would be on the same line, which may not be what you desire.