R Markdown PDF 中的图标题

3 r figure r-markdown

我想知道如何让我的标题出现在 R Markdown 中的图形上方。

这是一个工作示例:

---
title: "Practical"
output:
  pdf_document:
    fig_caption: yes
    latex_engine: xelatex
---

```{r fig1, echo=FALSE, fig.cap="\\label{fig:fig1}Caption"}
x <- 1:10
y <- 11:20
plot(x, y)
```
Run Code Online (Sandbox Code Playgroud)

这个问题之前已经在这里提出过,但建议的代码似乎对我不起作用。

Mic*_*per 6

当 RMarkdown 运行时,它使用 pandoc 将基本文档转换为 LaTeX 文档。因此,我们的 LaTeX 包可以在文档中使用,这有助于实现这样的高级定制。

在这种情况下,可以使用Floatrow 包将标题重新定位在图上方。这很大程度上是基于之前的答案。可以通过header-includes在 YAML 中包含参数来加载它,如下所示:


title: "Practical"
output:
  pdf_document:
    fig_caption: yes
    latex_engine: xelatex
header-includes:
   - \usepackage{floatrow}
   - \floatsetup[figure]{capposition=top}
---


```{r fig1, echo=FALSE, fig.cap="\\label{fig:fig1}Caption"}
x <- 1:10
y <- 11:20
plot(x, y)
```
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述