haozhu233 / kableExtra

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

Duplicated rows with \vphantom issue again #564

Open eeholmes opened 4 years ago

eeholmes commented 4 years ago

This is a new version of previous issues #433 , #161 , #145 . The problem reappeared when I used column_spec(). Was fine without.

toydata <- data.frame(Var1 = c(1,2,2,3), Var2 = c("Hello", "\\kern 1em", "\\kern 1em", "\\kern 1em"))
toydata %>% kable(align="lc", caption="Test", escape=FALSE, booktab=TRUE, longtable=TRUE, format="latex") %>%
  column_spec(1, latex_column_spec="p{8em}")

The \vphantom is inserted between the \kern and 1em thus breaking the LaTeX code.

mv-p commented 3 years ago

I'm having a similar issue with vphantom being inserted for rows that have the same set of values. However, I'm using pack_rows and getting this issue.

toydata <- data.frame(Var1 = c("1973","1974", "1973", "1974"), Var2 = c("0", "2", "0", "5")) toydata %>% kbl(caption="Test", booktab=TRUE, format="latex") %>% kable_styling(full_width = T, font_size = 6) %>% pack_rows("AMF", 1,2) %>% pack_rows("UMF", 3,4)

vincentarelbundock commented 1 year ago

This line inserts \vphantom{} before the first non whitespace character, which breaks when the line ends with \kern 1em

https://github.com/haozhu233/kableExtra/blob/master/R/util.R#L239