Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set padding in header cells of htmlTable package?

Tags:

r

I am using htmlTable package in my rmarkdown files. For setting cell padding I use this piece of code:

htmlTable(..., css.cell = "padding-left: .5em; padding-right: .2em;")

How can I do something similar on the header cells?

like image 713
rdatasculptor Avatar asked Jan 08 '23 11:01

rdatasculptor


1 Answers

The key is to add the + 1 rows when specifying the css.cell matrix argument. The default is to only affect the data-cells. Here's an example:

simple_output <- matrix(1:4, ncol = 2)
htmlTable(simple_output,
          header = LETTERS[1:2],
          css.cell = rbind(rep("background: lightgrey; font-size: 2em; padding-left: .5em; padding-right: .2em;", 
                               times = ncol(simple_output)),
                           matrix("", 
                                  ncol = ncol(simple_output), 
                                  nrow = nrow(simple_output))))
like image 106
Max Gordon Avatar answered Jan 21 '23 13:01

Max Gordon