Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kableExtra column_spec width not working

I am creating tables that will be rendered using Rmarkdown to HTML. I am using kable and have been experimenting with kableExtra to add features to my tables. I am not able to get the width option in column_spec to work when applying it to all columns in a table:

data.frame(RRmin=1, RRmax=10) %>%
   dplyr::rename(`Reportable Range Min` = RRmin, `Reportable Range Max` = RRmax) %>%
   kable() %>%
   column_spec(1:2, width = "0.5in") %>%
   kable_styling(c("bordered", "condensed"), full_width = F)

This gives a table that looks like this. I can make the width longer and both columns change, but when it goes smaller it does not seem to work. I can make one column smaller but not the other:

data.frame(RRmin=1, RRmax=10) %>%
   dplyr::rename(`Reportable Range Min` = RRmin, `Reportable Range Max` = RRmax) %>%
   kable() %>%
   column_spec(1, width = "0.5in") %>%
   kable_styling(c("bordered", "condensed"), full_width = F)

This gives a table that looks like this. The first column was appropriately changed but I cannot get this effect when I'm trying to change the size of both columns. I have tried doing separate column_spec lines for each column, using escape=F and am not sure what to try next.

like image 889
kr32 Avatar asked Jul 31 '18 12:07

kr32


1 Answers

I have had similar problems with column_spec not working. I was able to find a fix that worked for my purposes by playing with the width_min option. Maybe that will help.

My issue was that none of the columns widths seemed to be adjusted by column_spec, even when I tried all of the options you mention above. The result was that some columns were way too thin. I set width_min="3in" and fixed it. This was not a perfect fix because now I'm left with other column that are too wide, but it at least made my table a little more readable.

like image 193
user11029980 Avatar answered Oct 07 '22 18:10

user11029980