如何更改flextable中set_caption的大小和字体

问题描述 投票:0回答:1

我希望能够使用 R 中的 flextable 包中的 set_caption() 来格式化我的 flextable 标题。我知道如何格式化除标题之外的表格的所有其他部分。我希望标题为“Arial”10p 字体,而不是斜体。

示例数据

df = structure(list(Col.A = c("x", "x", "x", "x", "x", "x", "x", "x", 
"x", "x", "x", "x", "x", "x", "x"), Col.B = c("x", "x", "x", 
"x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x"), 
    Group = c("Group1", "Group1", "Group1", "Group1", "Group1", 
    "Group2", "Group2", "Group2", "Group2", "Group2", "Group3", 
    "Group3", "Group3", "Group3", "Group3"), Variable = c("V1", 
    "V2", "V3", "V4", "V5", "V1", "V2", "V3", "V4", "V5", "V1", 
    "V2", "V3", "V4", "V5")), class = "data.frame", row.names = c(NA, 
-15L))

如何制作柔性表

myft <- flextable(df, cwidth = c(1,1,4,1) ) %>% bg(i = NULL, j = NULL, bg = "#333D47", part = "header") %>% 
  color(i = NULL, j = NULL, color = "white", part = "header") %>% 
  bold(i = NULL, j = NULL, bold = TRUE, part = "header") %>% 
  fontsize(i = NULL, j = NULL, size = 10) %>% theme_box() %>% set_caption(caption = paste0("Table 1"))

myft

r caption flextable
1个回答
0
投票

根据我对文档的理解,您可以通过

as_paragraph()
as_chunk()
定义标题来实现您想要的结果,这允许设置文本属性,如下所示:

library(flextable)
library(magrittr)

myft <- flextable(df, cwidth = c(1, 1, 4, 1)) %>%
  bg(i = NULL, j = NULL, bg = "#333D47", part = "header") %>%
  color(i = NULL, j = NULL, color = "white", part = "header") %>%
  bold(i = NULL, j = NULL, bold = TRUE, part = "header") %>%
  fontsize(i = NULL, j = NULL, size = 10) %>%
  theme_box() %>%
  set_caption(
    caption = as_paragraph(
      as_chunk(
        "Table 1",
        props = fp_text_default(font.size = 10, font.family = "Arial")
      )
    )
  )

myft

© www.soinside.com 2019 - 2024. All rights reserved.