如何移除Rmarkdown生成HTML中并排Kable上方的多余水平线
I’ve run into this exact issue before! That annoying extra line at the top comes from the default top border added by the outer kable_styling() call when you combine tables with kables(). Here’s how to get rid of it:
Solution: Disable the Top Border in Outer Styling
Just add the border_top = FALSE argument to the final kable_styling() call. This tells kableExtra not to draw that top border around the combined table container, while keeping all the styling you applied to the individual tables intact.
Modified Code
kables(list( kable(df1) %>% kable_styling(bootstrap_options = c("striped", "bordered"), full_width = F) %>% row_spec(0, bold = T) %>% pack_rows("Pack some rows here", 1, 2, label_row_css = "background-color: #666; color: #fff;") %>% pack_rows("Pack some rows here", 3, 4, label_row_css = "background-color: #666; color: #fff;"), kable(df2) %>% kable_styling(bootstrap_options = c("striped", "bordered"), full_width = F) %>% row_spec(0, bold = T) %>% pack_rows("Pack some rows here", 1, 2, label_row_css = "background-color: #666; color: #fff;") %>% pack_rows("Pack some rows here", 3, 4, label_row_css = "background-color: #666; color: #fff;") )) %>% kable_styling(border_top = FALSE) # Add this argument here
Why This Works
When you use kables() to arrange tables side-by-side, the outer kable_styling() wraps the entire set of tables in a container. By default, this container gets a top border—exactly the line you’re trying to remove. Setting border_top = FALSE explicitly turns off that default behavior without affecting the borders inside your individual tables.
Give this a try, and that extra line should disappear completely!
内容的提问来源于stack exchange,提问作者benson23

