我正在尝试创建一个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.
如果有人有一些提示可以让我在我的标题上方放置一个图像(logo.png),这将是很棒的。
答案 0 :(得分:12)
根据以前的解决方案,以下代码不需要辅助header.tex
文件。所有内容都包含在.Rmd
文件中。而是在YAML标头的header-includes
块中定义LaTeX命令。可以找到更多信息here。
将下面的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.
答案 1 :(得分:2)
对于 beamer 演示文稿,您可以这样做:
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"
titlegraphic将放在标题文本
下面