[英]How to add a caption *above* a table with `knitr::kable`?
當我將一個簡單的 Rmarkdown 文檔呈現為github_document
,表格標題出現在表格下方而不是上方。 它還缺少“表:”前綴。 有什么辦法可以改變這種行為嗎? kable
已經明確kable
的默認標題位置應該在表格上方,當我在 Rmarkdown 文件之外運行相同的命令時,標題確實出現在頂部。
我所指的命令是
knitr::kable(mtcars, caption = "mtcars")
我的 Rmarkdown 文檔如下所示:
---
title: "Test"
output: github_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
knitr::kable(mtcars, caption = "mtcars")
```
指定format = "pipe"
或format = "simple"
似乎沒有幫助。
當轉換為降價輸出格式knitr::kable()
將默認為format = "pipe"
。 這是用於 pandoc 的管道表。 format = "simple"
用於 Pandoc 的簡單表。
這兩種語法是 Pandoc 的降價語法。 Pandoc 支持提供標題( https://pandoc.org/MANUAL.html#extension-table_captions )。
knitr會為你寫:表格和標題的預期格式。
但是,輸出定義為 Github gfm
Markdown,因此 Pandoc 的gfm
。 這種 Markdown 風格不支持標題。 因此 Pandoc 將在另一個 Markdown 表中轉換管道表並抑制標題語法以將文本放置在表格下方。 這是潘多克在做的。
拿這個.md
文件
Table: Demonstration of pipe table syntax.
| Right | Left | Default | Center |
|------:|:-----|---------|:------:|
| 12 | 12 | 12 | 12 |
| 123 | 123 | 123 | 123 |
| 1 | 1 | 1 | 1 |
進行 pandoc 轉換將導致
❯ pandoc -t gfm test.md
| Right | Left | Default | Center |
|------:|:-----|---------|:------:|
| 12 | 12 | 12 | 12 |
| 123 | 123 | 123 | 123 |
| 1 | 1 | 1 | 1 |
Demonstration of pipe table syntax.
當輸出為gfm
時,Pandoc 將標題放在下面
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.