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
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!