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

时间:2018-07-02 20:20:51

标签: r latex r-markdown kable

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

  1. 如何使标题标签加粗?
  2. 如何在标题标签后添加换行符?例如,我要在“表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)

1 个答案:

答案 0 :(得分:1)

您可以使用LaTeX的caption软件包来控制PDF输出。我们需要更改此文件的某些设置来完成您的更改,但是这些可以作为单独的.tex文件包含在内,或者在这种情况下只需进行少量更改即可,我们只需插入它们直接放在最前面。这是一个最小的示例:

---
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)
```

enter image description here

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

  

如果您想对样式进行更多更改,请在此处查看包装文档:http://anorien.csc.warwick.ac.uk/mirrors/CTAN/macros/latex/contrib/caption/caption-eng.pdf