简体   繁体   English

使用徽标图像启动 rmarkdown 报告

[英]Start rmarkdown report with logo image

I'd like to create a report, but my report need to be start with a logo.我想创建一份报告,但我的报告需要以徽标开头。 In my example, I try to do:在我的示例中,我尝试这样做:

Here is the.rmd file (say, cylinder.rmd)这是 .rmd 文件(比如 cylinder.rmd)

---
```{r echo=FALSE, out.width = "30%", fig.align = "center"}
knitr::include_graphics("R_logo.png")
```
title: "cylinder_report"
author: "author_name"
date: "2023-01-25"
output: pdf_document
params:
  cylinder: 0
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
df = mtcars
```


## Cylinder `r params$cylinder`
```{r output, echo=FALSE}
knitr::kable(df[df$cyl == params$cylinder,])
```

And my separated file is:我的分离文件是:

library(knitr)
library (rmarkdown)
data(mtcars)
cyls = unique(mtcars$cyl)
for(cyl in cyls) {
  rmarkdown::render(
    input = "cylinder.Rmd",
    output_file = paste0("cylinder_report_", cyl),
    params = list(cylinder = cyl)
  )
}
#

This code doesn't work, but for better comprehension my desirable output must to be:这段代码不起作用,但为了更好地理解我想要的 output 必须是:

报告1

Please any help with it?请帮忙吗?

The solution was find in: https://bookdown.org/yihui/rmarkdown-cookbook/latex-logo.html解决方案在: https://bookdown.org/yihui/rmarkdown-cookbook/latex-logo.html

The .Rmd needs to be: .Rmd需要是:

---
title: "cylinder_report"
author: "author_name"
date: "2023-01-25"
output: pdf_document
params:
  cylinder: 0
header-includes:
  - \usepackage{titling}
  - \pretitle{\begin{center}
    \includegraphics[width=2in,height=2in]{R_logo.png}\LARGE\\}
  - \posttitle{\end{center}}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
df = mtcars
```


## Cylinder `r params$cylinder`
```{r output, echo=FALSE}
knitr::kable(df[df$cyl == params$cylinder,])
```

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM