在docx中为flextable添加标题 [英] add caption to flextable in docx
本文介绍了在docx中为flextable添加标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将标题添加到呈现给docx的弹性表中? 目的是产生一个适当的标题,该标题可以在文档中引用以产生表和内联引用的列表.
How could one add a caption to a flextable rendered to docx? The aim is to produce a proper caption which can be referenced within the document to produce a list of tables and inline references.
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
推荐答案
我使用以下方式为表格添加标题.
I use the following way to caption tables.
#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)
to cross-reference the table use \@ref(tab:TC1)
使用表格生成列表
<!---BLOCK_TOC{seq_id: 'tab'}--->
这篇关于在docx中为flextable添加标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文