是否可以为gt表的列标签行添加边框?例如:
# 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
显示包含“A”的行的底部边框,但不显示列标签(即 Column_1、Column_2 等)的底部边框。
这是由于 CSS 规则冲突造成的,其中应用于顶部表格主体(和底部列标签)之间边框的默认样式优先于您尝试应用的新样式。 可以通过将该边框现有的样式规则设置为无来解决。
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")