kableExtra column_spec width not working

kable paged table
kable vertical lines
kableextra row_spec
kable change row names
kable collapse_rows
kable total row
kable combine two tables
kable in shiny

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.


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.

column_spec doesn't always work with width for HTML · Issue #242 , The root cause of this problem is that the width of the header rows should also be I am creating some tables using the kable extra package. column_spec doesn't always work with width Was hoping to get to use kableExtra for some reports I need to do this fall but they need to be in a very standard


This may be a little late, but I've just been working with the kableExtra package, and it seems that your code is now working pretty much as is.

At first I thought it might have something to do with the ordering of the kable_styling component, but it seems not to matter which order it is in. Perhaps it was a bug in the package that has since been fixed. It is also immaterial wether you use column_spec(column = 1:2, width = "2in"), or column_spec(1:2, width = "2in"). Both seem to work well, as do modifications to the columns size. See below:

---
output: pdf_document
---

```{r global_options, include=FALSE}
# Just some setup:

sapply(c("knitr", "tidyverse", "kableExtra"), require, character.only = TRUE)

options(knitr.kable.NA = '', knitr.table.format = "latex")

knitr::opts_chunk$set(fig.path = 'figures/',
                  echo = FALSE, warning = FALSE, message = FALSE)

opts_chunk$set(echo = FALSE,
           message = FALSE,
           warning = FALSE,
           fig.align = "center",
           fig.width = 5,
           fig.pos = 'H',
           as.is = TRUE)
```

```{r variable-names-table, as.is=TRUE}
# Size example 1; 1.5 inch columns
data.frame(RRmin=1, RRmax=10) %>%
    dplyr::rename(`Reportable Range Min` = RRmin, `Reportable Range Max` = RRmax) %>%
   kable() %>%
   kable_styling(c("bordered", "condensed"), full_width = F) %>%
   column_spec(column = 1:2, width = "1.5in")

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

# To set columns 1 and two to different sizes
data.frame(RRmin=1, RRmax=10) %>%
    dplyr::rename(`Reportable Range Min` = RRmin, `Reportable Range Max` = RRmax) %>%
   kable() %>%
   column_spec(column = 1, width = "3in") %>%
   column_spec(column = 2, width = "2in") %>%
   kable_styling(c("bordered", "condensed"), full_width = F)

```

Just a note for anyone else dealing with the issue. The above will run as an RMD

R version 3.6.1, on mac RStudio 1.2.1335 kableExtra 1.1.0 knitr 1.25 tidyverse 1.2.1

column_spec function, From kableExtra v1.1.0 by Hao Zhu column_spec(kable_input, column, width = NULL, bold = FALSE, italic = FALSE, NOT RUN { x <- knitr::kable(head(mtcars), "html") column_spec(x, 1:2, width = "20em", bold = TRUE, italic = TRUE) # } I have a table that is being printed. I've specified column width in the column_spec function , however the titles of my columns are not wrapping to fit the specified width. Code looks like this;


Simply replace width by width_min!

kableExtra column_spec width not working, 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  Hi I find that column_spec with background color does not appear to be working with longer datframes. So for example when I do. dt <- mtcars[1:5, 1:6] kable(dt, format = "latex", booktabs = T, caption = "Demo Table") %>% kable_styling(la


column_spec: Specify the look of the selected column in kableExtra , width_max defines the maximum width of table columns. extra_css. Extra css text to be passed into the cells of the row. Note that it's not for the whole column but  With this width_min, you can set up a column with a width that won't collapse even when the window is not wide enough. width_max. Only for HTML table. width_max defines the maximum width of table columns. extra_css. Extra css text to be passed into the cells of the row. Note that it's not for the whole column but to each individual cells


Create Awesome HTML Table with knitr::kable and kableExtra, By default, a bootstrap table takes 100% of the width. to specified the column width for different column, since the auto adjust in HTML may not work in its Similar with column_spec , you can define specifications for rows. Also, the third column is somehow dropped on top of the second for some reason, and citations are not working too. The MWE below is based on this related SO question, which only needs 2 columns: kable: Vertical alignment does not work with pdf output


[PDF] kableExtra, BugReports https://github.com/haozhu233/kableExtra/issues. Depends R column_spec(kable_input, column, width = NULL, bold = FALSE,. kableExtra is NOT a table generating package. It is a package that can "add features" to a kable() output using a syntax that every useR loves - the pipes %>% . We see similar approaches to deal with plots in packages like ggvis and plotly .