在 rmarkdown pdf 的标题页中添加图像 [英] add image in title page of rmarkdown pdf

查看:60
本文介绍了在 rmarkdown pdf 的标题页中添加图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am attempting to create an rmarkdown document. I have finally figured out a way to approach this, although it has taken quite some time. The last thing I would like to be able to do is to add an image to the title page of my pdf document.

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

The trouble I have is that my title page is defined by the top section of YAML. Below is the contents of my example.Rmd file. I use the Knit PDF button in RStudio to turn it into a 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) 那就太好了.

If anyone has some tips that would allow me to put an image (logo.png) above my title that would be great.

推荐答案

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

I was able to solve this using LaTeX package titling

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

header.tex 应该包含以下代码:

Where the header.tex should include the following code:

usepackage{titling}

pretitle{%
  egin{center}
  LARGE
  includegraphics[width=4cm,height=6cm]{logo.png}\[igskipamount]
}
posttitle{end{center}}

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

and replace logo.png with the image you would like to use and make sure the file is in the root directory of your Rmd file. You can change image width and height to your needs. For more information on available options go to titling

这篇关于在 rmarkdown pdf 的标题页中添加图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆