davidgohel / flextable

table farming
https://ardata-fr.github.io/flextable-book/
558 stars 80 forks source link

Captions in pdf output ignore line breaks ("\n") #663

Open ian-curtis opened 2 weeks ago

ian-curtis commented 2 weeks ago

I am not sure if this is a flextable issue or not but I figured I'd start here. See the example below. Is "\n" not supported for pdf output? I checked ?set_caption and I see mostly notes in there about HTML and Word output. Should I be setting pdf captions a different way?

My .Rmd file....

---
title: "Flextable test"
date: "2024-10-03"
output:
  pdf_document:
    latex_engine: xelatex
---

'''{r}
library(flextable)
library(tibble)

tibble(
  x = seq(0, 10, 1),
  y = seq(100, 200, 10),
  z = seq(1000, 2000, 100)
) %>% flextable() %>% 
  set_caption(as_paragraph(as_chunk("Hey Hey This is the Caption \n Wow Another Line \n And Another Line")))
'''

....produces excellent HTML output....

Screenshot 2024-10-03 at 9 52 12 AM

....but has a funky pdf caption when knitted using knitr....

Screenshot 2024-10-03 at 9 53 03 AM

(Using bookdown::pdf_document2 produces this same issue).

Any thoughts? Maybe a piece of the manual or a closed issue I missed?

R version 4.4.1 (2024-06-14)
Platform: aarch64-apple-darwin20
Running under: macOS Sonoma 14.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Detroit
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] tibble_3.2.1    flextable_0.9.6

loaded via a namespace (and not attached):
 [1] vctrs_0.6.5             zip_2.3.1               cli_3.6.3               knitr_1.48             
 [5] rlang_1.1.4             xfun_0.47               textshaping_0.4.0       gdtools_0.4.0          
 [9] data.table_1.16.0       glue_1.7.0              openssl_2.2.2           askpass_1.2.0          
[13] htmltools_0.5.8.1       ragg_1.3.2              fansi_1.0.6             fontquiver_0.2.1       
[17] rmarkdown_2.28          grid_4.4.1              evaluate_1.0.0          fastmap_1.2.0          
[21] yaml_2.3.10             lifecycle_1.0.4         bookdown_0.40           compiler_4.4.1         
[25] officer_0.6.6           fontLiberation_0.1.0    pkgconfig_2.0.3         Rcpp_1.0.13            
[29] rstudioapi_0.16.0       systemfonts_1.1.0       digest_0.6.37           R6_2.5.1               
[33] utf8_1.2.4              pillar_1.9.0            magrittr_2.0.3          uuid_1.2-1             
[37] fontBitstreamVera_0.1.1 tools_4.4.1   

When submitting a new issue:

davidgohel commented 1 week ago

thanks, I can reproduce. I don't know what causes this weird alignment for now :(