Reputation: 8437
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?
Upvotes: 4
Views: 1920
Reputation: 5467
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))))
Upvotes: 9
Reputation: 1
New to R I really appreciate this fantastic htmlTable package thank you Max Gordon.
The +1 did not work for me for some reasons (I have some tspanner?).
You can still do the formatting by adding the html code to your rownames, e.g. I want to format in italic the NA's rows header in my table:
rl[which(rl == "NA's")] <- rep("<i>NA's", length(which(rl == "NA's")))
Where rl is the vector of my rows headers
Hope it helps
Upvotes: 0