如何将kable标题/字幕集中在r左右对齐时

发布于 2025-01-29 17:19:47 字数 259 浏览 5 评论 0原文

我想将表格的标题(标题)居中为中心,但是分配了列的值。我还希望我的字幕分为两行,每行都被居中。

Align选项以相同的方式更改两个。

head(mtcars) %>%
   kbl(caption = "{first row\\\\  
                    second row}",
          align = "l") %>%
   kable_styling()

I want to have the title(caption) of the table centered, but the values of columns left assigned. I also want my caption to be broken into two lines and each line to be centered.

align option changes both of them in a same way.

head(mtcars) %>%
   kbl(caption = "{first row\\\\  
                    second row}",
          align = "l") %>%
   kable_styling()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失退 2025-02-05 17:19:47

也许这会有所帮助:

head(mtcars) %>%    
    kbl(align = "l") %>% 
    add_header_above(data.frame("{first row \\\\ second row}", 12), 
                     monospace = TRUE) %>%
    kable_styling()

结果:

”在此处输入图像说明“

更新

我假设您正在尝试以HTML格式生产表。为了中心标题并在字幕文本上放置线路断开,您可以使用HTML元素:<中心>用于中心和< br>进行折断。

head(mtcars) %>%
    kbl(caption = "<center>{first row <br>
                  second row}</center>", 
        align = "l") %>% 
    kable_styling()

结果:

“在此处输入图像描述”

参考

  1. 格式字幕
  2. href =“ https://developer.mozilla.org/en-us/docs/web/html/element” rel =“ nofollow noreferrer”> httpps://deverice.mozilla.mozilla.org/en-us/docs/docs/web/ html/元素

Maybe this helps:

head(mtcars) %>%    
    kbl(align = "l") %>% 
    add_header_above(data.frame("{first row \\\\ second row}", 12), 
                     monospace = TRUE) %>%
    kable_styling()

The result:

enter image description here

Update

I assume that you are trying to produce a table in html format. To center the caption and put a line break on the caption texts, you can use html elements: <center> for centering and <br> for line breaking.

head(mtcars) %>%
    kbl(caption = "<center>{first row <br>
                  second row}</center>", 
        align = "l") %>% 
    kable_styling()

The result:

enter image description here

References

  1. Format captions in kableExtra()
  2. https://developer.mozilla.org/en-US/docs/Web/HTML/Element
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文