如何在同一横向页面上添加具有多列的柔性表和文本
How to add a flextable and text with multiple columns on same landscape page
我想在同一个 word landscape 文档上同时创建 table 和列格式的文本。
问题是每当我添加 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,50), collapse = ' ')) %>%
body_end_section_columns_landscape() %>%
print(target = "test.docx")
它为文本添加了第二页。
是否有可能在同一页面上同时显示横向和纵向的内容?
谢谢
是的,函数 body_end_section_*
在各部分之间添加了一个分页。您需要添加特定的部分设置 (type = "continuous") 并使用 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")
我想在同一个 word landscape 文档上同时创建 table 和列格式的文本。
问题是每当我添加 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,50), collapse = ' ')) %>%
body_end_section_columns_landscape() %>%
print(target = "test.docx")
它为文本添加了第二页。
是否有可能在同一页面上同时显示横向和纵向的内容?
谢谢
是的,函数 body_end_section_*
在各部分之间添加了一个分页。您需要添加特定的部分设置 (type = "continuous") 并使用 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")