0

I have almost got the perfect table for a Latex report I am drafting with the kable package in rMarkdown. One thing I can't get quite right is the vertical alignment of the collapsed rows.

Using the sample code from the kableExtra documentation reproduces my problem:

collapse_rows_dt <- data.frame(C1 = c(rep("a", 10), rep("b", 5)),
C2 = c(rep("c", 7), rep("d", 3), rep("c", 2), rep("d", 3)),
C3 = 1:15,
C4 = sample(c(0,1), 15, replace = TRUE))
kbl(collapse_rows_dt, booktabs = T, align = "c") %>%
column_spec(1, bold=T) %>%
collapse_rows(columns = 1:2, latex_hline = "custom", custom_latex_hline = 1:2, valign = "top")

This almost works, so close...but the vertical alignment is not consistent across the columns. This makes it unreadable when the table runs over multiple pages.

Vertical alignment not consistent across columns

valign= "bottom" works perfectly though.

Consistent vertical alignment when aligned to the bottom of the collapsed row.

  • This information would benefit from a graphic visualization, but you would have to construct datasets for this type of sample testing – Daniel_j_iii Aug 12 '22 at 18:44
  • I see what doesn't work and what works but doesn't seem to be what you want. What does the idea placement look like to you? Can you draw it by hand and upload an image of that placement? BTW, @Daniel_j_iii makes a GREAT point. Questions that are reproducible tend to get great answers a lot faster. Check it out: [making R reproducible questions](https://stackoverflow.com/q/5963269). – Kat Aug 13 '22 at 04:09

1 Answers1

0

The issue is with "booktabs = T". With it set to "F", the vertical alignment is perfect.