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

查看:359
本文介绍了在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中的编织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 打包标题

---
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{%
  \begin{center}
  \LARGE
  \includegraphics[width=4cm,height=6cm]{logo.png}\\[\bigskipamount]
}
\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天全站免登陆