kableExtra::pack_rows() - grouping not working for last row in long table and no indentation for wrapped text

前端 未结 1 1994
小蘑菇
小蘑菇 2021-01-03 15:54

I use the kableExtra package to generate a long table in an R markdown documents knitted to PDF.

Sets of rows of the table are grouped together using

相关标签:
1条回答
  • 2021-01-03 16:26

    I don't have enough reputation to comment so I'll have to leave this as an answer even though it's only a partial answer to the second part of your question. There is a way to remove all indentation in the pack_rows() function by using indent=FALSE:

    kable(dt, 
      escape = FALSE, # to be able to include latex commands
      booktabs = T, 
      longtable = TRUE, # allow long table to span multiple pages
      ) %>% 
      kable_styling(full_width = F,
                    latex_options = c(
                      "repeat_header"  # repeat header of long table
                    )
      ) %>% 
      # column characteristics: set widths
      column_spec(1, width = "2cm") %>%
      # group rows together and give these groups labels
      pack_rows("Mazda Cars", 1, 2, indent=FALSE) %>%
      pack_rows("Datsun Cars", 3, 3, indent=FALSE)
    

    Unfortunately my table is quite long and would be much more readable if I could find a way to indent both parts of my long row name. So I'm still hoping for a better answer to this question. But I hope this helps someone!

    0 讨论(0)
提交回复
热议问题