r - kableExtra 将等式保存为 png 或 jpg

标签 r kable kableextra

我正在尝试将 kableExtra 表保存到包含方程式的 png 中。

一个非常简单的例子:

tab <- kable("$a^2$")
tab

这给了我正在寻找的表格:

enter image description here

现在我想使用 save_kable 将其保存为 png 或 jpg 文件

save_kable(tab, file = "test.jpg")

然后返回这个:

enter image description here

我已经尝试更改 escape 参数,但结果保持不变

tab <- kable("$a^2$", escape = TRUE)
tab <- kable("$a^2$", escape = FALSE)

有什么想法可以确保 png 或 jpg 文件也呈现方程式/数学符号吗?

谢谢!

最佳答案

我提出了一种基于其他两个包的解决方案:

library(knitr)
library(gridExtra) # to display a table
library(latex2exp) # for TeX function which transform $$ to expression

png("test.png")
grid.table(TeX(kable("$a^2$", format = "simple")))
dev.off()

escape 仅适用于 kable() 中的 colnames。

关于r - kableExtra 将等式保存为 png 或 jpg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67889007/

相关文章:

r - Monty Hall In R - setdiff 意想不到的结果

r - Kable 表,其中第一列为 "stacked"的 booktabs 和 Collapse_rows 在 R/Rstudio/tinytex 更新后无法生成 pdf

r - knitr::kable() 中的短标题

r - kableExtra 仅在演示文稿中有另一个表格时才有效?

r - [R] 中的 kableExtra 突然崩溃

rmarkdown & kable/kableextra : Printing % symbol in Table when using escape = F

R函数范围: want to see the return value on next iteration

r - R 中具有时间条件的子集数据集

r - 在 R 中,dataframe[-NULL] 返回空数据帧

r - 如何使用 kable 将表格中一列中选定行中的文本设为斜体?