Problem aligning a table body with title footnotes in a docx file

Problem aligning a table body with title footnotes in a docx file
I am using the clinify package with flextable to generate a docx file. My issue is lining up the table body with the title footnotes. I tried using: set_table_properties(width = 1, layout = "autofit") to resolve this, but it didn't work. Sample code: # Load packages for program execution pkg.load <- c("tidyverse", "flextable", "officer", "clinify") invisible(lapply(pkg.load, library, character.only = TRUE)) test.df <- iris |> select(Species, Sepal.Length, Sepal.Width, Petal.Length, Petal.Width) |> group_by(Species) |> mutate( grp = cur_group_id(), descr = paste0("Property for Species: ", Species)) |> ungroup() ## Convert to clinify object tbl.cln1 <- flextable(test.df) |> merge_v(j = c("Species")) |> # Trying to set autofit window set_table_properties(width = 1, layout = "autofit") |> as_clintable() # Column layout tbl.cln <- tbl.cln1 |> clin_page_by(page_by = "grp", max_rows = 25) |> clin_group_by("descr") |> clin_col_widths(Sepal.Length = 0.15, Sepal.Width = 0.15, Petal.Length = 0.15, Petal.Width = 0.15) # Add title footnote to CLIN Object tbl.cldoc <- tbl.cln |> clin_add_titles( list( c("Client: XXXXXX", "Page {PAGE} of {NUMPAGES}"), c("Protocol: R Sample", "Data Extraction Date: 01JAN2025"), c("Table 15.1.1.1"))) |> clin_add_footnotes( list( c("Property of flower species in R package."), c(paste0('Generated on:',format(Sys.time(), '%d%b%Y %I:%H:%M'))))) # Write out docx file write_clindoc( x = tbl.cldoc, file = paste0(study.env$g_outputpath, "/", "Test.docx") ) Output: Output I want, achieved using "Autofit to Window" manually on the docx file: This question was flagged similar to: flextable autofit in a Rmarkdown to word doc causes table to go outside page margins The problem is similar to the other question. However, with Rmarkdown syntax, it was not clear to me how to apply the solution. My example here is building the syntax with FLEXTABLE and passing the information to CLINIFY for DOCX creation. I think this example can help other folks, so I am not deleting this question. @Tim helped me answer this question already, so I am not requesting to open this for answers. I would like to mark this as answered, but not sure how to do it.

Take Your Experience to the Next Level

New

Download our mobile app for a faster and better experience.

Comments

0
U

Join the discussion

Sign in to leave a comment

0:000:00