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).
---
title: Adding a Logo to LaTeX Title
author: Michael Harper
date: December 7th, 2018
output: pdf_document
header-includes:
- \usepackage{titling}
- \pretitle{\begin{center}
\includegraphics[width=2in,height=2in]{logo.jpg}\LARGE\\}
- \posttitle{\end{center}}
---
<!-- Optionally include a page break. This will force the start
of the document to the second page -->
\newpage
This is your report.
```{r, include=FALSE}
# copy the R logo to the current directory
file.copy(file.path(R.home("doc"), "html", "logo.jpg"), '.')
```
An example output is shown in Figure 6.1.

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:
title: |
{width=1in}
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 {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.
 我的书签
 我的书签
                                 添加书签
 添加书签 移除书签
 移除书签