Kev*_* Ho 10 r knitr r-markdown
我想编一个报告,使标题类似于下图。
我目前遇到三个问题
请在下面找到最小的可重现示例(请注意,我对在线图像进行了评论,因为我不知道如何正确编码)
---
output: pdf_document
geometry: margin=0.25in
classoption:
- landscape
---
```{r, echo=FALSE, results='asis'}
for (i in unique(iris$Species)) {
cat("\\newpage")
# cat('\n\n')
cat("\n#", "Iris Species Summary", "\\hfill", paste0("Exhibit ", grep(i, unique(iris$Species)), ".1"))
cat("\n##", i, "\\hfill", "(Gross)")
cat("\n######", "(000's)", "\\hfill", as.character(Sys.Date()))
}
```
Run Code Online (Sandbox Code Playgroud)
你的三个问题都可以通过包含元素来解决html。
RMarkdown本质上是一个Markdown,你可以在文件中包含html元素。
您可以通过以下方式使用 html:
```{r echo=FALSE}
knitr::asis_output(htmltools::htmlPreserve("
<div>
<div>block 2
</div>
</div>
"))
```
Run Code Online (Sandbox Code Playgroud)
或者
<!--html_preserve-->
<div>
<div>block 3
</div>
</div>
<!--/html_preserve-->
Run Code Online (Sandbox Code Playgroud)
然后你可以使用html来改变文档中的布局和字体,基本上你需要学习编写简单的html代码,不难只是大量谷歌搜索。
很抱歉没有为您写出示例代码,它应该很简单。参考资料在这里,这是一个已关闭的 GitHub 问题: https: //github.com/rstudio/rmarkdown/issues/326。
希望这可以帮助。