1

I want to create on the same word landscape document both a table and text formatted in column. The problem is that whenever I add body_end_section_columns_landscape() it creates a new page.

Example of working code in portrait format:

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")

If I try to create similar in landscape

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")

It adds a second page for the text.

Is there a possibility to have both on same page as landscape same as in the portrait one?

Thank you

Arkadi w
  • 129
  • 22

1 Answers1

2

Yes, functions body_end_section_* are adding a break page between sections. You need to add specific section settings (type = "continuous") and use body_end_block_section() to achieve what you want to do:

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

David Gohel
  • 9,180
  • 2
  • 16
  • 34