1

If I need a bit of control about table width, due to automatic multirow not always working great, I can display wider than 100% table with a scroll_box. I can manually control the table width by setting table.attr = 'style="width: 200%"', i.e. the table being twice as wide as the document, meaning I can see half of the table width in the scroll box.

However, when I want to use some kable_styling, this breaks down. Some automatic width scaling is used, that makes nonsense multirow table that looks ugly.

I want to used the striped styling but keep my width setting.

Even the "full_width = TRUE" argument is not respected and the table is narrowed by the kable_styling.

# Generate example data
dt <- data.table(
    Name = c('Adam', 'Bronn', 'Caligula'),
    Description = c(
        "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
        "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
        "Lorem ipsum dolor sit amet, consectetuer adipiscing elit."
    ),
    Age = c(25, 30, 35),
    Salary = c(50000, 60000, 70000)
)
for(x in LETTERS){
    dt[[x]] <- rnorm(3) %>% round(3)
}

# Correctly display wide table with scroll_box
kable(dt, table.attr = 'style="width: 200%"') %>% 
    scroll_box(width = '100%')

# Break the setting with kable_styling
kable(dt, table.attr = 'style="width: 200%"') %>% 
    kable_styling('striped', full_width = TRUE) %>%
    scroll_box(width = '100%')

Petr Hála
  • 11
  • 1
  • Try adding `format = "html"` to the `kable` function. I'm not sure "striped" is a html option. – Peter Jun 09 '23 at 15:35
  • Did not help. Options are basic, striped, bordered, hover, condensed, responsive and none. – Petr Hála Jun 12 '23 at 11:01
  • Ok, so I found a working, but not really nice solution. The problem is that kable_styling did set max-width attribute. As such, the overall attribute must be: table.attr = 'style="width: 200%; max-width: 200%;"') – Petr Hála Jun 12 '23 at 14:10
  • That's great. You should answer your own question formally so that the community as a whole benefits: https://stackoverflow.com/help/self-answer, However, you may require more reputation. – Peter Jun 12 '23 at 15:54

0 Answers0