微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在同一个横向页面上添加具有多列的柔性表和文本

如何解决如何在同一个横向页面上添加具有多列的柔性表和文本

我想在同一个Word Landscape文档上创建表格和以列格式设置的文本。 问题在于,每当我添加 body_end_section_columns_landscape()时,它都会创建一个页面

纵向格式的工作代码示例:

library(officer)
library(flextable)


ft <- qflextable(head(iris))
read_docx() %>%
  body_add_flextable(value = ft ) %>%
  body_end_section_continuous() %>% 
  body_add_par(value = paste(rep(letters,50),collapse = ' ')) %>% 
  body_end_section_columns() %>% 
  print(target = "test.docx")

如果我尝试在横向景观中创建类似图片

ft <- qflextable(head(iris))
read_docx() %>%
  body_add_flextable(value = ft ) %>%
 body_end_section_landscape() %>% 
  body_add_par(value = paste(rep(letters,collapse = ' ')) %>% 
  body_end_section_columns_landscape() %>% 
  print(target = "test.docx")

它将为文本添加第二页。

是否可以同时将两张画像和一幅画像放在同一张画像上?

谢谢

解决方法

是的,函数body_end_section_*在各节之间添加了一个分页。您需要添加特定的部分设置(类型=“连续”)并使用body_end_block_section()来实现您想要的操作:

library(officer)
library(magrittr)
library(flextable)

landscape_one_column <- block_section(
  prop_section(
    page_size = page_size(orient = "landscape"),type = "continuous"
  )
)
landscape_two_columns <- block_section(
  prop_section(
    page_size = page_size(orient = "landscape"),type = "continuous",section_columns = section_columns(widths = c(4,4))
  )
)

ft <- qflextable(head(iris))

read_docx() %>%
  
  # there starts section with landscape_one_column
  body_add_flextable(value = ft) %>%
  body_end_block_section(value = landscape_one_column) %>%   # there stops section with landscape_one_column
  
  # there starts section with landscape_two_columns
  body_add_par(value = paste(rep(letters,50),collapse = " ")) %>%
  body_end_block_section(value = landscape_two_columns) %>%  # there stops section with landscape_two_columns
  print(target = "test.docx") 

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。