Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting a column separator in KableExtra

I have the following table created using kableExtra. I'm looking for a way in which I can add a vertical border between columns c and d (to seperate the content under the two headers.) Also, is there a way to change the color of the cells in an entire column (lets say the third column?)

library(dplyr)
library(kableExtra)

a <- c('First', 'Second', 'Third')
b <- c(1,2,3)
c <- c(4,5,6)
d <- c(7,8,9)
e <- c(10,11,12)

df <- data.frame(a,b,c,d,e)

kable(df) %>% 
  kable_styling() %>% 
  add_header_above(c("","Header 1" = 2, "Header 2" = 2), bold = T)

enter image description here

like image 270
sa90210 Avatar asked Oct 18 '25 19:10

sa90210


1 Answers

Try:


kable(df) |> 
  kable_styling() |> 
  add_header_above(c("", "Header 1" = 2, "Header 2" = 2), bold = TRUE) |> 
  column_spec(4, border_left = TRUE) |> 
  column_spec(3, background = "lightgreen")

enter image description here

like image 50
Peter Avatar answered Oct 20 '25 10:10

Peter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!