You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何移除Rmarkdown生成HTML中并排Kable上方的多余水平线

Fix the Extra Horizontal Line Above Side-by-Side Kable Tables

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 12:42:45