How can I subscript names in a table from kable()?

别说谁变了你拦得住时间么 提交于 2019-12-05 14:31:42

To add subscripts in a rmarkdown document, you can embed your text between two tilde: text~sub~. When using function kable, any text in the table is recognized as markdown syntax. So that your rmarkdown code should be:

```{r}
A <- data.frame(round(replicate(3, runif(2)),2))
rownames(A) <- c("Hola~123~", "Hola~234~")
names(A) <- c("X~1~", "X~2~", "X~3~")
knitr::kable(A)
```

Just one note about bamphe's response is that the correct code is misspelled. It should be \\textsubscript{}. It is missing the second "t".

And completing the answer, you might choose to use the arguments row.names and col.names inside kable, in this way:

A <- data.frame(round(replicate(3, runif(2)),2))

rownames(A) <- c("Hola\\textsubscript{123}", "Hola\\textsubscript{234}")

knitr::kable(A,
             row.names = T,
             col.names = c("X\\textsubscript{1}", "X\\textsubscript{2}", "X\\textsubscript{3}"),
             escape = F)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!