为 table 的一个单元格添加上标,格式为 kable / kableExtra for Rmarkdown
Add a superscript to one cell of a table formatted with kable / kableExtra for Rmarkdown
我在 table 中有一个脚注,格式为 kable 和 kableExtra,用于 Rmarkdown 生成的 pdf。我需要 NYC 有上标 (NYC^1
) 来指向脚注,但不知道该怎么做。有什么建议吗?
df <- data.frame(city=c("NYC","LA","CHI","MIA"),
score=sample(1:100, 4, replace=T))
library(kableExtra)
library(kable)
kable(df,
digits = 2,
format = "latex",
align="c",
row.names = FALSE,
booktabs=T) %>%
kable_styling(bootstrap_options = c("hover"),
full_width = F,
font_size = 12,
position = "left") %>%
footnote(number = c("2017 data missing"))
我没有合适的答案给你。这是一种通过替换生成的乳胶字符串中的字符串来破解它的方法。
library(kableExtra)
library(stringr)
df <- data.frame(city=c("NYCHACKIT","LA","CHI","MIA"),score=sample(1:100, 4, replace=T))
tmp <- knitr::kable(df,
digits = 2,
format = "latex",
align="c",
row.names = FALSE,
booktabs=T) %>%
kable_styling(bootstrap_options = c("hover"),
full_width = F,
font_size = 12,
position = "left") %>%
footnote(number = c("2017 data missing"))
knitr::asis_output(str_replace(tmp, "HACKIT", "$^{1}$"))
我在 table 中有一个脚注,格式为 kable 和 kableExtra,用于 Rmarkdown 生成的 pdf。我需要 NYC 有上标 (NYC^1
) 来指向脚注,但不知道该怎么做。有什么建议吗?
df <- data.frame(city=c("NYC","LA","CHI","MIA"),
score=sample(1:100, 4, replace=T))
library(kableExtra)
library(kable)
kable(df,
digits = 2,
format = "latex",
align="c",
row.names = FALSE,
booktabs=T) %>%
kable_styling(bootstrap_options = c("hover"),
full_width = F,
font_size = 12,
position = "left") %>%
footnote(number = c("2017 data missing"))
我没有合适的答案给你。这是一种通过替换生成的乳胶字符串中的字符串来破解它的方法。
library(kableExtra)
library(stringr)
df <- data.frame(city=c("NYCHACKIT","LA","CHI","MIA"),score=sample(1:100, 4, replace=T))
tmp <- knitr::kable(df,
digits = 2,
format = "latex",
align="c",
row.names = FALSE,
booktabs=T) %>%
kable_styling(bootstrap_options = c("hover"),
full_width = F,
font_size = 12,
position = "left") %>%
footnote(number = c("2017 data missing"))
knitr::asis_output(str_replace(tmp, "HACKIT", "$^{1}$"))