I am trying to output a Word document using a formatted company reference_doc.
The issues are that:
- The document should be in book format with mirror margins: alternating left/right margins on odd and even pages.
- The footer should include page numbers (right aligned on odd pages and left aligned on odd pages) and author’s name on odd pages and document title on even pages.
- Page numbers should appear first on page 6.
Intended margins and footer format
So is my yaml front matter:
---
title: "Document Title"
author: "Author Name"
output:
officedown::rdocx_document:
reference_docx: reference_doc.docx
page_size:
width: 6.18
height: 8.78
orient: "portrait"
page_margins:
bottom: 0.87
top: 0.71
right: 0.87
left: 0.98
header: 0.49
footer: 0.24
gutter: 0
---
Using fpar and prop_section functions in Officer/Officedown packages, I have been about to produce different text in footer on odd and even pages, but I have no idea how I can add page numbers.
knitr::opts_chunk$set(echo = FALSE, fig.cap = TRUE)
library(officedown)
library(officer)
right_template <- function(txt) {
block_list(
fpar(values = txt,
fp_p = fp_par(text.align = "right", padding.top = 0,
padding.bottom = 22, padding.right = 13),
fp_t = fp_text_lite(font.size = 9, font.family = "Trade Gothic Next",
color = "black", bold = FALSE)
)
)
}
left_template <- function(txt) {
block_list(
fpar(values = txt,
fp_p = fp_par(text.align = "left", padding.top = 0,
padding.bottom = 22, padding.left = 13),
fp_t = fp_text_lite(font.size = 9, font.family = "Trade Gothic Next",
color = "black", bold = FALSE)
)
)
}
sec_pr <- prop_section(
page_size (width = 6.18 , height = 8.78, orient = "portrait"),
page_mar(
top = 0.71,
bottom = 0.98,
left = 0.98,
right = 0.71,
header = 0.49,
footer = 0.24,
gutter = 0.0),
footer_default = left_template("Author Name"),
footer_even = right_template("Document Title")
)
Do you have any idea how I can produce mirror (alternating) margins and add page numbers? I can share the reference_doc if needed.
I have tried to first set (mirror) margins and edit the footer in the reference_doc, but when I knit, (the output Word has all the styles as per reference_doc) the footer is empty and the margins are default.