简体   繁体   English

在表格下方添加另一个标题

[英]add another caption below table with kable

in R markdown, knitting to PDF, kable allows to include a 'caption' (which really is a table title), but I'd like to add another caption below the table in smaller font . 在R markdown(编织为PDF)中,kable允许包含“标题”(实际上是表格标题),但是我想在表格下方较小的字体添加另一个标题。 Any ideas how to do that? 任何想法如何做到这一点? (I don't want to just add text below in the main markdown doc because then it's number and not part of the table float). (我不想只在markdown主文档中添加文本,因为那是数字,而不是表格浮动的一部分)。

Here's some code example: 这是一些代码示例:

library(knitr)
name <- c('Na~2~O', 'Ca', 'Ba')
value <- c(2,3,5)
data <- data.frame(name, value)
rownames(data) <- data[,1]
data$name <- NULL
kable(data, format = "pandoc", caption = 'some title')

You could use xtable . 您可以使用xtable For that you need to put your data into a list and give it an attribute "message". 为此,您需要将数据放入列表中,并为其赋予一个属性“消息”。

```{r table1, results='asis', message=FALSE, echo = FALSE}
data <- list(data)
attr(data, "message") <- c("\\textit{Note: }Here you can enter some", 
                           "text as your desired caption",
                           "there's somewhere a workaround",
                           "not needing to put in text like this",
                           "but at least it works.")

library(xtable)
print(xtableList(data, caption="some title")
      , caption.placement = "top"
      , sanitize.text.function = identity
      )
```

Yields 产量

在此处输入图片说明

Data 数据

name <- c('Na\\textsubscript{2}O', 'Ca', 'Ba')
value <- c(2,3,5)
data <- data.frame(name, value)
rownames(data) <- data[,1]
data$name <- NULL

Note: In addition, for better formatting this solution should also be applicable here (not tried yet though). 注意:此外,为了更好地格式化, 此解决方案也应在此处适用(但尚未尝试)。

Using the kable function, here is how to do it from this page: https://haozhu233.github.io/kableExtra/awesome_table_in_html.html 使用kable函数,此页面的操作方法如下: https ://haozhu233.github.io/kableExtra/awesome_table_in_html.html

That page is just a good resource in general. 该页面通常只是一个很好的资源。 Here is what they say regarding footnotes: 他们对脚注说的是:

There are four notation systems in footnote, namely general, number, alphabet and symbol. 脚注中有四种表示法,即通用,数字,字母和符号。 The last three types of footnotes will be labeled with corresponding marks while general won't be labeled. 脚注的最后三种类型将标记相应的标记,而一般标记将不标记。 You can pick any one of these systems or choose to display them all for fulfill the APA table footnotes requirements. 您可以选择这些系统中的任何一个,或选择全部显示它们以满足APA表脚注的要求。

kable(dt, align = "c") %>% 
kable_styling(full_width = F) %>%
footnote(general = "Here is a general comments of the table. ",
       number = c("Footnote 1; ", "Footnote 2; "),
       alphabet = c("Footnote A; ", "Footnote B; "),
       symbol = c("Footnote Symbol 1; ", "Footnote Symbol 2"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM