gpt4 book ai didi

r - 在 docx 中为 flextable 添加标题

转载 作者:行者123 更新时间:2023-12-03 16:26:50 24 4
gpt4 key购买 nike

如何向呈现为 docx 的 flextable 添加标题?
编辑:目的是生成一个适当的标题,可以在文档中引用以生成表格和内联引用的列表。

iris.t <-
iris[1:5,] %>%
regulartable() %>%
style(pr_c = officer::fp_cell(vertical.align = "bottom",
border.bottom = officer::fp_border(width = 2)), part = "header") %>%
rotate(j = names(iris)[-c(1:2)],
rotation = "tbrl", part = "header", align = "bottom") %>%
height(height = max(dim_pretty(., part = "header")$widths), part = "header") %>%
width(width = dim_pretty(.,part = "body")$widths)

iris.t

最佳答案

我使用以下方式为表格添加标题。

#set the table caption styling
knitr::opts_chunk$set(tab.cap.pre = "Table ", tab.cap.sep = ": ")

#set the table caption styling
set_flextable_defaults(font.family = "Calibri (Body)",
font.size = 9,
digits = 0,
border.color = "#000000",
padding.bottom = 1,
padding.top = 1,
padding.left = 3,
padding.right = 1)

ft <- flextable(df, defaults = TRUE) #convert to flextable object
autonum <- run_autonum(seq_id = "tab", bkm = "TC1", bkm_all = TRUE) # number the table, bkm (bookmark) is important as the cross-referencing is done using the bookmark
ft <- set_caption(ft, caption = "Traffic Counts for Existing Condition",
style = "Table Caption", autonum = autonum)
ft # to print the table
交叉引用表使用\@ref(tab:TC1)
生成表列表使用
<!---BLOCK_TOC{seq_id: 'tab'}--->

关于r - 在 docx 中为 flextable 添加标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49676982/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com