Different autofit behavior between simple table and flextable #552
-
Hi @davidgohel, hope your well, I have to print table with very long concatenated strings, and the behavior to calculate width of columns between simple table in officer and using flextable is very different. Example : library(officer)
library(flextable)
temp <- data.frame(colonne_1 = c("1", "2"),
colonne_2 = paste0(rep("toto", 50), collapse = ", "))
doc <- read_docx()
# simple table
doc <- body_add_table(doc, temp)
doc <- body_add_par(doc, "")
# flextable
tempft <- flextable(temp)
doc <- body_add_flextable(doc, tempft)
doc <- body_add_par(doc, "")
# with autofit
tempft2 <- flextable(temp)
tempft2 <- autofit(tempft2)
doc <- body_add_flextable(doc, tempft2)
print(doc, "my_doc.docx") Autofit for simple table is perfect. Do I miss something ? Is there an option to apply autofit behavior of simple tables into flextables ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Hello Gilles, This should set real Word autofit:
PS : sorry for the naming issue, it's historical...
More here: https://ardata-fr.github.io/flextable-book/layout.html#tabwidth |
Beta Was this translation helpful? Give feedback.
Hello Gilles,
This should set real Word autofit:
PS : sorry for the naming issue, it's historical...
autofit()
set the width to the calculated width of the max paragraph length (and only\n
can be used otherwise it is considered to be layout on a single row),set_table_properties(layout = "autofit")
dedicate the autofit work to the sofware that will be used to view the table (browser for HTML, adobe for PDF, Word for docx)More here: https://ardata-fr.github.io/flextable-book/layout.html#tabwidth