Skip to content

Landscape is not correctly reflected in RTF files #351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
humberto-garciacaballero opened this issue May 9, 2025 · 1 comment
Open
Labels
bug Something isn't working

Comments

@humberto-garciacaballero

Summary

When exporting tables in RTF using landscape, the resulting RTF is not correctly recognized by some RTF viewers (at least MS Word). This results in them considering the document to have a custom size. This seems to be due to the following option being missing in the resulting RTF file:

\lndscpsxn

According to the RTF spec (https://www.biblioscape.com/rtf15_spec.htm), that option is defined as:

Page orientation is in landscape format. To mix portrait and landscape sections within a document, the \landscape control should not be used so that the default for a section is portrait, which may be overridden by the \lndscpsxn control.

The following example can be used to generate two RTF files: one in portrait and another one in landscape. They both are A4.

library(rtables)

tbl <- lyt <- basic_table() %>%
  split_cols_by("ARM") %>%
  analyze(c("AGE"), function(x, ...) {
      in_rows(
        "Mean (sd)" = c(mean(x), sd(x)),
        "Median" = median(x),
        "Min - Max" = range(x),
        .formats = c("xx.xx (xx.xx)", "xx.xx", "xx.xx - xx.xx")
      )
  }) %>%
  build_table(ex_adsl)

export_as_rtf(tbl, "portrait.rtf", page_type = "a4")
export_as_rtf(tbl, "landscape.rtf", landscape = TRUE, page_type = "a4")

By opening the portrait file, we can see that Word correctly recognizes it as an A4 in portrait mode. On the other hand, if we open the landscape file, we can see that word does not recognize its size as A4 anymore. At this point, if we add \lndscpsxn before declaring the size of the document (\lndscpsxn\paperw16834\paperh11909), and we open the new file, we can see that word recognizes the size of the document correctly as A4 and its orientation as landscape.

R session info

R version 4.4.3 (2025-02-28)
Platform: aarch64-apple-darwin20
Running under: macOS Sequoia 15.4.1

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

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

time zone: Europe/Madrid
tzcode source: internal

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

loaded via a namespace (and not attached):
[1] compiler_4.4.3

OS / Environment

  • OS: MacOS Sequoia 15.4.1
@humberto-garciacaballero humberto-garciacaballero added the bug Something isn't working label May 9, 2025
@Melkiades
Copy link
Contributor

We do not fully support rtf outputs. We do use {rtables.officer} package for exporting to docx as main output

If you want to attempt a fix I can review your PR straightforward 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants