0

When I print large flextable to Word using Officer, the header will appear on a separate page than the table itself. For example

test = read.table(text = 'columnA columnB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB
TextA TextB',
sep = ",",
header = T)

test = test %>% flextable()

read_docx() %>%
  body_add_par("Table Test", style = "table title") %>% 
  body_add_flextable(value = test) %>%
  print(doc, target = paste0("../../Table Test.docx"))

Generates this:

enter image description here

One answer suggested the solution was to change Knitr options to the following:

knitr::opts_chunk$set(tab.topcaption = TRUE,
                      ft.split = T,
                      ft.keepnext = F) 

But this doesn't seem to work. Doesn't anybody have any ideas?

Parseltongue
  • 11,157
  • 30
  • 95
  • 160
  • You need to update the package version to the latest version (CRAN or github for a fresher version). You can also use `ft.keepnext = FALSE` – David Gohel Oct 18 '22 at 07:17
  • Thanks! Updating it worked! Quick follow-up while you're here: The table header is always formatted in Cambria instead of Times New Roman. Do you know how to change this and make it left aligned? I've done this, but it doesn't work `font(x, part = "all", fontname = "Times New Roman") x <- align(x, align = "left", part = "header")` – Parseltongue Oct 18 '22 at 14:22

0 Answers0