Alignment/fitting 的 flextable 到 R 中的页面宽度

Alignment/fitting of a flextable to page width in R

我正在创建一个非常基本的报告,将小的 tables 添加到循环中的 docx。 我想让它们适合页面的宽度,或者至少将 table(不是单元格的内容)对齐到左侧。 这应该是一件很容易的事,但我只找到了与以下相关的参考资料:

我尝试了参考资料中建议的解决方案,但它们没有用。 这是我正在使用的(注释行以显示其他尝试):

  tbl.params = flextable(fdata) %>%
    delete_part(part = "header") %>%
    #autofit() %>%
    border_remove() %>%
    border_inner_h(part="body", border = small_border ) %>%
    hline_top( border = big_border, part="body") %>%
    bold(j=1) %>%
    set_table_properties(layout = "autofit")
    #fit_to_width(7.5)

我是不是弄错了或遗漏了什么? 我正在寻找“纯”Officer(如果可用)的解决方案。

以下脚本在 docx 文档中添加一个 flextable。 withs列由Word调整,table左对齐:

library(officer)
library(flextable)

ftab <- flextable( head( mtcars ) )
ftab <- set_table_properties(ftab, layout = "autofit")
doc <- read_docx()
doc <- body_add_flextable(doc, value = ftab, align = "left")
print(doc, target = "fileout.docx")