在rmarkdown pdf的标题页中添加图片

Dan*_*Dan 12 pdf r rstudio r-markdown

我正在尝试创建一个rmarkdown文档.我终于找到了解决这个问题的方法,尽管已经花了很长时间.我希望能做的最后一件事是将图像添加到我的pdf文档的标题页.

我遇到的麻烦是我的标题页是由YAML的顶部定义的.以下是我的example.Rmd文件的内容.我使用RStudio中的Knit PDF按钮将其转换为PDF.

---
title: "This is a my document"
author: "Prepared by: Dan Wilson"
date: '`r paste("Date:",Sys.Date())`'
mainfont: Roboto Light
fontsize: 12pt
documentclass: report
output: 
  pdf_document:
    latex_engine: xelatex
    highlight: tango
---
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>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r}
summary(cars)
```

You can also embed plots, for example:

```{r, echo=FALSE}
plot(cars)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
Run Code Online (Sandbox Code Playgroud)

如果有人有一些提示,可以让我把图像(logo.png)放在我的标题之上,那将是很棒的.

小智 15

我能够使用LaTeX软件包标题来解决这个问题

---
title: "Untitled"
author: "Name"
date: "September 19, 2015"
output:
  pdf_document:
    includes:
      in_header: header.tex
---

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

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r}
summary(cars)
```

You can also embed plots, for example:

```{r, echo=FALSE}
plot(cars)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
Run Code Online (Sandbox Code Playgroud)

header.tex应包含以下代码:

\usepackage{titling}

\pretitle{%
  \begin{center}
  \LARGE
  \includegraphics[width=4cm,height=6cm]{logo.png}\\[\bigskipamount]
}
\posttitle{\end{center}}
Run Code Online (Sandbox Code Playgroud)

并替换logo.png为您要使用的图像,并确保该文件位于Rmd文件的根目录中.您可以根据需要更改图像宽度和高度.有关可用选项的更多信息,请转到标题


Meg*_*ron 14

根据以前的解决方案,以下代码不需要辅助header.tex文件.所有内容都包含在.Rmd文件中.而是header-includes在YAML标头的块中定义LaTeX命令.更多信息可以在这里找到.

my_graphic.png下面替换为您的本地图形文件.

---
title: "A title page image should be above me"
header-includes:
- \usepackage{titling}
- \pretitle{\begin{center}\LARGE\includegraphics[width=12cm]{my_graphic.png}\\[\bigskipamount]}
- \posttitle{\end{center}}
output: 
  pdf_document:
    toc: true
---

\newpage

# Section 1

Some text.
Run Code Online (Sandbox Code Playgroud)


lok*_*oki 6

对于投影仪演示,您可以这样做:

title: "Title"
subtitle: "Subtitle"
author: "author"
date: "date"
header-includes:
- \titlegraphic{\centering \includegraphics[width=12cm]{titlepic.png}}
output: 
  beamer_presentation:
    latex_engine: xelatex
    theme: "metropolis"
    highlight: "espresso"
classoption: "aspectratio=169"
Run Code Online (Sandbox Code Playgroud)

标题图形将放置在您的标题文本下方