删除在 R 中使用 kbl 创建的表中的分隔线

Removing Separator Line in Table Created with kbl in R

提问人:estrix 提问时间:10/5/2023 更新时间:10/5/2023 访问量:28

问:

我正在使用 R 并使用 kableExtra 创建了一个表。我的表格包括以美元为单位的类别、计数和值,在“计数”、“值”、“(n)”和“以美元为单位”下有副标题。表格已经有一些水平线,但我想进一步自定义它。

具体来说,我想: 删除“计数”、“值”、“(n)”和“以美元为单位”下的水平线。 将其他现有水平线保留在表格中。

感谢您的帮助!

# Load the required libraries
library(kableExtra)
library(dplyr)

# Create example data (you can customize this to your data)
data <- data.frame(
  Category = c("Toyota", "Honda", "Ford", "Nissan"),
  Count = c(50, 60, 45, 55),
  Minimum = c(100, 110, 95, 105),
  Maximum = c(200, 210, 195, 205)
)

# Create the table
table <- kbl(data, booktabs = TRUE) %>%
  kable_styling(latex_options = c("striped"), font_size = 10, position = "center") %>%
  add_header_above(c(" " = 1, "(n)" = 1, "in Dollars" = 2)) %>%
  add_header_above(c(" " = 1, "Count" = 1, "Values" = 2))

# Display the table
table
R 乳胶 Kable

评论


答:

1赞 Julian 10/5/2023 #1

您可以使用来删除水平线,即line = FALSE

# Create the table
table <- kbl(data, booktabs = TRUE) %>%
  kable_styling(latex_options = c("striped"), font_size = 10, position = "center") %>%
  add_header_above(c(" " = 1, "(n)" = 1, "in Dollars" = 2), line = FALSE) %>%
  add_header_above(c(" " = 1, "Count" = 1, "Values" = 2), line = FALSE)

enter image description here