减少字幕和桌子之间的填充

发布于 2025-01-27 08:09:12 字数 920 浏览 3 评论 0原文

我正在使用Flextable循环循环,以在列表中的每个元素中生成字幕和表格,以在rmarkDown文档中生成表。虽然我可以成功地渲染字幕和表格,但字幕和表之间的填充/边距太大,我找不到减少它们的方法。这是我到目前为止所拥有的:

---
title: "Untitled"
output: html_document
date: '2022-05-09'
---

``{r setup, include=FALSE}
library(flextable)
library(magrittr)
``

``{r results='asis', echo=FALSE, ft.align="left"}

my_list<-list()
my_list$ds1<-head(mtcars, 5)
my_list$ds2<-head(mtcars, 10)

for (i in 1:length(my_list)) {
  
  myft <- flextable(my_list[[i]]) %>% 
    set_caption(paste("Caption ", i))
  
  flextable_to_rmd(myft)
  
}
``

我认为也许使用Flextable :: Padding()会有所帮助,但这似乎只能控制表行中的填充,而不是页面上的元素之间的间距。

请注意,我已经在上面的代码示例中删除了一些所需的降压背板,以便可以在Stackoverflow上正确渲染。

在标题和表格之间“

I'm using flextable to loop over a list of data, generating captions and tables for each element in the list to generate tables in an rmarkdown document. While I can successfully render the captions and tables, the padding/margins between captions and tables is too large, and I can't find a way to reduce them. Here's what I have so far:

---
title: "Untitled"
output: html_document
date: '2022-05-09'
---

``{r setup, include=FALSE}
library(flextable)
library(magrittr)
``

``{r results='asis', echo=FALSE, ft.align="left"}

my_list<-list()
my_list$ds1<-head(mtcars, 5)
my_list$ds2<-head(mtcars, 10)

for (i in 1:length(my_list)) {
  
  myft <- flextable(my_list[[i]]) %>% 
    set_caption(paste("Caption ", i))
  
  flextable_to_rmd(myft)
  
}
``

I thought that perhaps using flextable::padding() would help, but this seems to only control the padding within the table rows, rather than the spacing between elements on a page.

Note that I've removed some of the required markdown backticks in the code sample above so that it can render correctly on Stackoverflow.

Unwanted padding between caption and top of the table

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

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

发布评论

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

评论(1

枫以 2025-02-03 08:09:12

将其添加到您的RMD中。不要将其放在代码块中 - 只是将其放置在您可以自由写的地方。

<style>
caption {
  padding-bottom: 0px;
}
</style>

目前,标题是用P标签编写的,周围是标题标签,周围有更多的P标签,所有这些标签都有填充,边距和线条高规格。这为您提供最大的努力(IMO)。

Add this to your RMD. Don't put it in a code chunk—just place it where you might otherwise free-write.

<style>
caption {
  padding-bottom: 0px;
}
</style>

Right now the caption is written in p tags, surrounded by caption tags, surrounded by more p tags, all of which have padding, margin, and line-height specs. This gives you the biggest bang for the least effort (IMO).

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文