gpt4 book ai didi

r - 在 rmarkdown pdf 的标题页中添加图像

转载 作者:行者123 更新时间:2023-12-04 00:05:52 26 4
gpt4 key购买 nike

我正在尝试创建一个 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),那就太好了。

最佳答案

基于前面的解决方案,下面的代码不需要辅助header.tex文件。所有内容都包含在.Rmd文件。 LaTeX 命令在 header-includes 中定义。 YAML header 中的 block 。更多信息可以找到here .

替换 my_graphic.png下面与您的本 map 形文件。

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

关于r - 在 rmarkdown pdf 的标题页中添加图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29389149/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com