Search code examples
rms-wordr-markdownofficedown

Unequal indentation in officedown R package


I'm using officedown package to generate MS Word documents. I noticed a strange and annoying issue. There are unequal indentation on left and right in the generated output (see the attached picture)

enter image description here

The Rmarkdown code I use:

---
output: officedown::rdocx_document
---

No actual content

I open the document with MS Word 2016 (desktop installation).

R sessionInfo output:

R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=Polish_Poland.1250  LC_CTYPE=Polish_Poland.1250    LC_MONETARY=Polish_Poland.1250 LC_NUMERIC=C                  
[5] LC_TIME=Polish_Poland.1250    

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

other attached packages:
[1] ggplot2_3.3.5    officedown_0.2.4

loaded via a namespace (and not attached):
 [1] zip_2.2.0         Rcpp_1.0.8.3      pillar_1.7.0      compiler_4.1.0    tools_4.1.0       digest_0.6.29     uuid_1.0-4       
 [8] evaluate_0.15     memoise_2.0.1     lifecycle_1.0.1   tibble_3.1.6      gtable_0.3.0      pkgconfig_2.0.3   rlang_1.0.2      
[15] DBI_1.1.2         cli_3.2.0         yaml_2.3.5        xfun_0.30         fastmap_1.1.0     withr_2.5.0       dplyr_1.0.8      
[22] officer_0.4.1     stringr_1.4.0     xml2_1.3.3        knitr_1.37        generics_0.1.2    vctrs_0.3.8       gdtools_0.2.4    
[29] systemfonts_1.0.4 tidyselect_1.1.2  grid_4.1.0        glue_1.6.2        R6_2.5.1          rvg_0.2.5         fansi_1.0.2      
[36] rmarkdown_2.13    bookdown_0.25     farver_2.1.0      purrr_0.3.4       magrittr_2.0.2    scales_1.1.1      htmltools_0.5.2  
[43] ellipsis_0.3.2    assertthat_0.2.1  colorspace_2.0-3  renv_0.15.4       labeling_0.4.2    utf8_1.2.2        stringi_1.7.6    
[50] munsell_0.5.0     cachem_1.0.6      crayon_1.5.0   

When I use bookdown::word_document2 as the output the issue is gone, so I expect there is something wrong with officedown package. However, the author doesn't allow new issues on GitHub.

I checked the default settings for page size and margins and they seem to be fine, i.e. margins are equal on both sides.

My first question is can you reproduce the strange behavior of officedown (I tested it on two different machines and in docker container, but MS Word 2016 only)? The second question - can it be fixed somehow?


Solution

  • You can define the margins you want to use (see ?rdocx_document argument page_margins):

    
    ---
    date: "`r Sys.Date()`"
    author: "Your Name"
    title: "officedown template"
    output: 
      officedown::rdocx_document:
        page_margins:
          bottom: .75
          top: .75
          right: 1
          left: 1
          header: 0.5
          footer: 0.5
          gutter: 0
    ---
    

    Github issues are closed, instead users are invited to open discussions https://github.com/davidgohel/officedown/discussions

    See https://github.com/davidgohel/officedown#questions-and-issues

    enter image description here