从 kable table 中删除斜体
Remove italics from kable table
我正在尝试将下标和上标添加到 kable table。我能够弄清楚如何添加上标和下标,但出于某种原因,它将字母变为斜体。我不知道如何删除斜体。任何帮助都会很棒。
我觉得我快要搞清楚了,我只是花了太多时间没有取得任何进展
这是一个数据示例
df <- structure(list(SNP = structure(1:21, .Label = c("a", "b", "c",
"d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p",
"q", "r", "s", "t", "u"), class = "factor"), Gene = structure(1:21, .Label = c("a",
"b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n",
"o", "p", "q", "r", "s", "t", "u"), class = "factor"), `Cases (338)` = c(87L,
86L, 72L, 71L, 70L, 69L, 67L, 58L, 55L, 54L, 52L, 50L, 48L, 47L,
47L, 46L, 45L, 45L, 43L, 43L, 42L), `% cases` = c(25.7, 25.4,
21.3, 21, 20.7, 20.4, 19.8, 17.2, 16.3, 16, 15.4, 14.8, 14.2,
13.9, 13.9, 13.6, 13.3, 13.3, 12.7, 12.7, 12.4), `p-value` = c(5.2,
6.3, 8.5, 1, 1.2, 1.4, 2, 1.1, 1.7, 2, 2.9, 4, 5.6, 6.6, 6.6,
7.8, 9.2, 9.2, 1.3, 1.3, 1.5), sub = structure(c(1L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L), .Label = c("$Example^{test}_{sub}$", "$Example^{test}$"
), class = "factor")), class = "data.frame", row.names = c(NA,
-21L))
这是我正在制作的table示例
kbl(table, format = "html", table.attr = "style='width:40%;'") %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>%
kable_classic(full_width = F, html_font = "Times New Roman")
如果你使用一些 LaTeX 代码,你可以实现你的目标。
.Label
变为:
.Label = c("$\mathrm{Example^{test}_{sub}}$", "$\mathrm{Example^{test}}$"
然后,将escape = F
选项添加到kbl
(顺便说一下,您需要使用df
,而不是table
):
kbl(df, format = "html", table.attr = "style='width:40%;'", escape = F) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>%
kable_classic(full_width = F, html_font = "Times New Roman")
最后的结果是:
我正在尝试将下标和上标添加到 kable table。我能够弄清楚如何添加上标和下标,但出于某种原因,它将字母变为斜体。我不知道如何删除斜体。任何帮助都会很棒。
我觉得我快要搞清楚了,我只是花了太多时间没有取得任何进展
这是一个数据示例
df <- structure(list(SNP = structure(1:21, .Label = c("a", "b", "c",
"d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p",
"q", "r", "s", "t", "u"), class = "factor"), Gene = structure(1:21, .Label = c("a",
"b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n",
"o", "p", "q", "r", "s", "t", "u"), class = "factor"), `Cases (338)` = c(87L,
86L, 72L, 71L, 70L, 69L, 67L, 58L, 55L, 54L, 52L, 50L, 48L, 47L,
47L, 46L, 45L, 45L, 43L, 43L, 42L), `% cases` = c(25.7, 25.4,
21.3, 21, 20.7, 20.4, 19.8, 17.2, 16.3, 16, 15.4, 14.8, 14.2,
13.9, 13.9, 13.6, 13.3, 13.3, 12.7, 12.7, 12.4), `p-value` = c(5.2,
6.3, 8.5, 1, 1.2, 1.4, 2, 1.1, 1.7, 2, 2.9, 4, 5.6, 6.6, 6.6,
7.8, 9.2, 9.2, 1.3, 1.3, 1.5), sub = structure(c(1L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L), .Label = c("$Example^{test}_{sub}$", "$Example^{test}$"
), class = "factor")), class = "data.frame", row.names = c(NA,
-21L))
这是我正在制作的table示例
kbl(table, format = "html", table.attr = "style='width:40%;'") %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>%
kable_classic(full_width = F, html_font = "Times New Roman")
如果你使用一些 LaTeX 代码,你可以实现你的目标。
.Label
变为:
.Label = c("$\mathrm{Example^{test}_{sub}}$", "$\mathrm{Example^{test}}$"
然后,将escape = F
选项添加到kbl
(顺便说一下,您需要使用df
,而不是table
):
kbl(df, format = "html", table.attr = "style='width:40%;'", escape = F) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>%
kable_classic(full_width = F, html_font = "Times New Roman")
最后的结果是: