Search code examples
rlatexkable

Removing Separator Line in Table Created with kbl in R


I'm working with R and have created a table using kableExtra. My table includes categories, counts, and values in Dollars, with subheadings under "Count," "Values," "(n)," and "in Dollars." The table already has some horizontal lines in place, but I'd like to customize it further.

Specifically, I want to: Remove the horizontal lines under "Count," "Values," "(n)," and "in Dollars." Keep the other existing horizontal lines in the table.

Thank you for your assistance!

# 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

Solution

  • you can use line = FALSE to remove horizontal lines, i.e.

    # 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