7

I am using kable to make tables of my data in RMarkdown. You can supposedly adjust column width using the column_spec command, however this seems to adjust only the columns of the data, itself, but does not also adjust the column width of my header row. So now my headers no longer line up with their associated column of data.

For example:

    y <- knitr::kable(head(mtcars), "html")
    column_spec(y, 1:4, width="5em")
Alison K.
  • 71
  • 1
  • 2
  • 3
    it's a bug introduced in kableExtra 0.6.0. I will fix it – Hao Oct 31 '17 at 20:02
  • I recently added css `display: inline-block;` for a more consistent column width behavior (see [this](https://stackoverflow.com/questions/46689392/make-html-table-columns-wider-prevent-words-from-wrapping-in-rmarkdown/46691360#46691360) ) but at the same time, it makes the column header unable to auto adjust to the column width in the table body. – Hao Oct 31 '17 at 20:15
  • @Hao - Thank you! I tried using `width="5em; display: inline-block;"` within the `column_spec()` command, but it doesn't seem to have changed anything - let me know if/when you have another solution! :) – Alison K. Oct 31 '17 at 20:45
  • oh, it's not a solution. I was saying the solution in the other post caused the problem – Hao Oct 31 '17 at 20:49
  • @Hao - ahh ok, I misunderstood - thanks for clarifying. – Alison K. Oct 31 '17 at 20:58
  • Fixed now. A quick bug fixing patch is on its way to CRAN. – Hao Oct 31 '17 at 21:20

1 Answers1

0

Author of kableExtra, Hao Zhu, mentioned in the comments that this was a bug in kableExtra 0.6.0 and fixed version was released. Looking at the commit history, this commit removing the inline-block style should be the fix.

At the time of writing this kableExtra is on version 0.9.0 already, so this shouldn't happen with the current version.

eis
  • 51,991
  • 13
  • 150
  • 199