admin管理员组文章数量:1125470
Is it possible to add borders to the column label row of a gt table? For example:
# Create a simple 4x4 data frame
data <- data.frame(
Column_1 = c("A", "B", "C", "D"),
Column_2 = c(1, 2, 3, 4),
Column_3 = c(5.5, 6.5, 7.5, 8.5),
Column_4 = c(TRUE, FALSE, TRUE, FALSE)
)
# Generate a `gt` table
gt_table <- data %>%
gt() %>%
tab_header(
title = "Simple 4x4 Table",
subtitle = "For Testing Column Labels"
) %>%
tab_style(
style = cell_borders(sides = "bottom", weight = px(1)),
locations = list(
cells_column_labels(),
cells_body(rows = 1)
)
)
# Display the table
gt_table
The bottom border for the row containing "A" appears, but the bottom border for the column labels (i.e Column_1, Column_2 etc) does not.
Is it possible to add borders to the column label row of a gt table? For example:
# Create a simple 4x4 data frame
data <- data.frame(
Column_1 = c("A", "B", "C", "D"),
Column_2 = c(1, 2, 3, 4),
Column_3 = c(5.5, 6.5, 7.5, 8.5),
Column_4 = c(TRUE, FALSE, TRUE, FALSE)
)
# Generate a `gt` table
gt_table <- data %>%
gt() %>%
tab_header(
title = "Simple 4x4 Table",
subtitle = "For Testing Column Labels"
) %>%
tab_style(
style = cell_borders(sides = "bottom", weight = px(1)),
locations = list(
cells_column_labels(),
cells_body(rows = 1)
)
)
# Display the table
gt_table
The bottom border for the row containing "A" appears, but the bottom border for the column labels (i.e Column_1, Column_2 etc) does not.
Share Improve this question edited Jan 9 at 7:13 lroha 34.2k4 gold badges53 silver badges63 bronze badges asked Jan 9 at 6:51 ZachZach 153 bronze badges1 Answer
Reset to default 1This is due to a CSS rule conflict where the default border style applied to the top table body and the bottom column labels (a border width of 2px) takes precedence over the new 1px rule. It can be resolved by setting the existing style rules for this border to none (or the width to <= 1px).
library(gt)
# Generate a `gt` table
data %>%
gt() %>%
tab_header(
title = "Simple 4x4 Table",
subtitle = "For Testing Column Labels"
) %>%
tab_style(
style = cell_borders(sides = "bottom", weight = px(1)),
locations = list(
cells_column_labels(),
cells_body(rows = 1)
)
) %>%
tab_options(column_labels.border.bottom.style = "none",
table_body.border.top.style = "none")
More info on border conflicts can be found here
本文标签: rAdding a border to the column label row in gtStack Overflow
版权声明:本文标题:r - Adding a border to the column label row in gt - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736667690a1946751.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论