Page margins in officer Word output

Hi,

My problem is relatively straightforward: how am we supposed to use page_mar function to set the margin properties of a Word document with the officer package? I could not find the answer on any forum or in the documentation of officer

# This does not work
library(officer)
library(magrittr)

str1 <- "Lorem ipsum dolor sit amet, consectetur adipiscing elit."

my_doc <- read_docx()
prop_section(
  page_size = page_size(),
  page_margins = page_mar(
    bottom = 1.25,
    top = 1.25,
    right = 1,
    left = 1.5,
    header = 0.75,
    footer = 0.75,
    gutter = 0
  )
)
my_doc <- my_doc %>%
  body_add_par(value = str1, style = "Normal")
print(my_doc, target = "testdoc.docx")

Any input will be greatly appreciated.

When you don't want to change the settings within the document you can try to store this in a template file, that is used. I think this contains the margins as well, I used this to define the layout of the headers etc.

my_doc <- read_docx("template_blank.docx")

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.