haozhu233 / kableExtra

Construct Complex Table with knitr::kable() + pipe.
https://haozhu233.github.io/kableExtra/
Other
689 stars 147 forks source link

pack_rows() with tabular = "tabularx" returns error #861

Open thmschk opened 1 week ago

thmschk commented 1 week ago

I am unable to use pack_rows() in combination with tabular = "tabularx", which produces an error.

library(kableExtra)
library(dplyr)
kbl(mtcars, format="latex", tabular = "tabularx", valign="{\\textwidth}") %>% kableExtra::pack_rows("XXX", 1,2)

# `error in seq.default(table_info$ncol) : 'from' must be a finite number`
thmschk commented 1 week ago

I dived into the code a bit to understand the problem and guess that magic_mirror_latex() can't handle tabularx. As far as I can see, the ifelse condition might be extended to include tabularx:

table_info$tabular <- ifelse(grepl("\\\\begin\\{tabular\\}", kable_input), "tabular", ifelse(grepl("\\\\begin\\{tabularx\\}", kable_input), "tabularx", "longtable"))