【问题标题】:Changing table background color to black and all font color to white using Formattable使用 Formattable 将表格背景颜色更改为黑色,将所有字体颜色更改为白色
【发布时间】:2021-02-03 17:08:40
【问题描述】:

我正在尝试使用 R 中的 Formattable 包将整个表格的背景颜色更改为黑色,并将所有字体颜色更改为白色。我知道您可以使用“span”,但这仅适用于列(如果我'我错了)。请随时分享您的想法或建议!

这是我目前所拥有的。如您所见,我使用了“跨度”,但它仅适用于列,但我想将颜色更改完全应用于整个表格(不仅仅是每一列):

color_change<-formatter("span", style = ~ style(color = "white",background-color="black")

widget_formattable = formattable(Table_Output,align = c("l", rep("r", NCOL(Table_Output) - 1)),list(Activity=color_change))

最终结果应该将整个表格显示为黑色背景颜色和白色字体。提前致谢!

【问题讨论】:

    标签: r formattable


    【解决方案1】:

    实际上,我不认为 formattable 可以做到这一点。如果我错了,请纠正我。我建议你看看 flextable。请参阅以下代码和输出:

    set_flextable_defaults(background.color = "black", font.color = "white")
    ft <- flextable(mtcars)
    

    https://ardata-fr.github.io/flextable-book/

    【讨论】:

      【解决方案2】:

      您可以在 table.attr 参数中定义全局表格样式。

      iris_sub <- iris[1:5,]
      
      formattable(iris_sub,   
                  table.attr = 'style="color: white; background-color: black";')
      

      【讨论】:

        猜你喜欢
        • 2020-04-03
        • 2014-01-19
        • 2013-04-20
        • 2019-02-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-07-01
        • 1970-01-01
        相关资源
        最近更新 更多