r - 更改表格边框的边框颜色 - Kable

标签 r knitr kableextra

我正在尝试在 R 中的特定列周围创建边框。我可以使用 kableExtra 包来做到这一点(如下所示)

iris <- datasets::iris

iris2 <- do.call(data.frame, aggregate(. ~ Species, iris, function(x) c(mean = mean(x), sd = sd(x))))

res2 <- kable(iris2,"html", col.names =  c("Species", "Mean", "SD", "Mean", "SD", "Mean", "SD", "Mean", "SD"),   align = c("r","c","c","c","c","c","c","c","c")) %>%
  kable_styling(bootstrap_options = c("striped", "hover")) %>%
  add_header_above(c(" " = 1, "Sepal Length" = 2, "Sepal Width" = 2, "Petal Length" = 2, "Petal Width" = 2))

print(res2)

res3<- column_spec(res2, c(2,4,6,8), border_left = TRUE, border_right = FALSE)

column_spec(res3, c(3,5,7,9), border_left = FALSE, border_right = TRUE)

这会在正确的位置创建我想要的边框,但我希望它们是灰色而不是黑色。我尝试使用 column_spec 函数中的 'color=' ,但它会将整个列变成灰色,而不仅仅是边框。
res3<- column_spec(res2, c(2,4,6,8), border_left = TRUE, border_right = FALSE, color = "#D8D7D7")
column_spec(res3, c(3,5,7,9), border_left = FALSE, border_right = TRUE, color = "#D8D7D7")

关于如何更改边框颜色的任何建议都会有所帮助!现在,我使用 getAnywhere() 来查看是否可以稍微更改函数。

最佳答案

使用 css 插入边框。这有效

column_spec(res3, c(3,5,7,9), border_left = "2px solid gray",
            border_right = "2px solid gray")

关于r - 更改表格边框的边框颜色 - Kable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48527544/

相关文章:

python - 根据已知角值估计数字矩阵?

r - 加法与乘法内存使用分配不当?

从一维 data.frame 中删除行并将其保留为 data.frame

r - matchit CEM - "subscript out of bounds"错误

生成 pdf 时 R knitr 错误 41(windows)

r - Blogdown kable 表格格式(丑陋)

r - 在包中包含 Rnw 文件

r - 将 R Shiny Page 导出为 PDF

javascript - 如何在我的 Rmarkdown html 输出中获取复制按钮,以将 R 代码中生成的表格复制到剪贴板?

r - 你能在 RMarkdown 中左对齐或加粗 Kable 的表格/图形标题吗?