在 R Markdown 中的标题标题后添加换行符

Add line break after caption title in R Markdown

我想更改 R Markdown 输出中字幕的样式,并有两个请求:

  1. 如何将标题标签设为粗体?
  2. 如何在标题标签后添加换行符?例如,我想在 "Table 1" 和标题之间输入一行。

这是一个例子:

caption <- 
  " April is the cruellest month, breeding
    Lilacs out of the dead land, mixing
    Memory and desire, stirring
    Dull roots with spring rain.
    Winter kept us warm, covering
    Earth in forgetful snow, feeding
    A little life with dried tubers.
    Summer surprised us, coming over the Starnbergersee
    With a shower of rain; we stopped in the colonnade,
    And went on in sunlight, into the Hofgarten,
    And drank coffee, and talked for an hour.
    Bin gar keine Russin, stamm’ aus Litauen, echt deutsch.
    And when we were children, staying at the arch-duke’s,
    My cousin’s, he took me out on a sled,
    And I was frightened. He said, Marie,
    Marie, hold on tight. And down we went.
    In the mountains, there you feel free.
    I read, much of the night, and go south in the winter."

kable(mtcars, format = 'latex', caption = caption)

您可以使用 LaTeX 中的 caption 包来控制 PDF 的输出。我们需要更改此文件的一些设置以实现您的更改,但这些设置可以作为单独的 .tex 文件包含,或者在这种情况下只需要进行一些更改,我们可以插入他们直接在 frontmatter 中。这是一个最小的例子:

---
output: pdf_document
header-includes:
   - \usepackage{caption}
   - \captionsetup{labelfont=bf, labelsep = newline}
---

```{r table1}
caption <- "your long long long caption"
knitr::kable(mtcars, caption = caption)
```

此方法仅适用于 LaTeX 输出(即 PDF)。

If you want to make more changes to the style, check out the package documentation here: http://anorien.csc.warwick.ac.uk/mirrors/CTAN/macros/latex/contrib/caption/caption-eng.pdf