You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to build a recto verso document with different odd and even headers and footers, based on a company template. I tried several approaches, but none works. I have made two reprex-templates (template1.docx and template2.docx) based on how our company template looks like. It is a two-sided document, hence the white pages. Basically there is a cover, the first real page contains an introduction (page numbering starts here), followed by a toc on page 3, after which the real text starts from page 5 onwards, with odd and even headers/footers. The last page contains our company logo and legal information. The following reprexcode generates the document with both templates. You can find the results that I get in reprex_template1_generated.docx and reprex_template2_generated.docx. The docs reprex_template1_expected.docx and reprex_template2_expected.docx are the outputs as I would wish them to be.
Reprex code:
library(tidyverse)
library(officer)
make_doc <- function(doc){
doc <- doc %>%
body_replace_text_at_bkm(bookmark = "replacement1", value = "Subtitle 1") %>%
body_replace_text_at_bkm(bookmark = "replacement2", value = "Subtitle 2") %>%
cursor_bookmark("introduction") %>%
body_replace_text_at_bkm(bookmark = "introduction", value = "Introduction") %>%
body_add_par("Hello!", style = "Normal") %>%
cursor_bookmark("title") %>%
body_replace_text_at_bkm(bookmark = "title", value = "This is the first title") %>%
body_add_fpar(fpar(ftext(text = "Text on odd page"), run_pagebreak(), ftext(text = "Text on even page"))) %>%
body_end_section_portrait() %>%
headers_replace_text_at_bkm(bookmark = "header_odd", value = "This is the odd header") %>%
headers_replace_text_at_bkm(bookmark = "header_even", value = "This is the even header") %>%
cursor_bookmark("toc") %>%
body_remove() %>%
cursor_backward() %>%
body_add_toc(level = 2, pos = "after")
}
doc1 <- read_docx("template1.docx")
make_doc(doc1)
print(doc1, target = "reprex_template1.docx")
doc2 <- read_docx("template2.docx")
make_doc(doc2)
print(doc2, target = "reprex_template2.docx")
Approach 1 uses template1.docx
This approach uses headers and footers which differ from section to section, by deselecting “Link to previous”. The option “Different Odd & Even Pages” has been selected in the template.
Things that go wrong:
“Different Odd & Even Pages” is not selected – page 6 also has the odd header/footer, whereas it should be even.
Second page (the back of the cover page): “Link to previous” is selected, contrary to the template (but this does not result in an error).
Page 4 (the back of the toc): “Link to previous” is selected”, contrary to the template: this results in an erroneous display of the page number (the page number should not be displayed at all).
Page 5 and 6: “Link to previous” is selected, contrary to the template: this results in not displaying the headers and the image in the footers; the page number is displayed.
Approach 2 uses template2.docx
This approach uses headers and footers which are the same on every page by selecting “Link to previous” for each new section. But because the headers and footers should not be visible on each page (for example the white back-pages), I had to hide them using a textbox. This is, however, an approach I’d rather not use …
Things that go wrong:
Again the even pages do not use the even header/footer – “Different Odd & Even Pages” is not selected. When I select this manually after generating the document, the headers and footers are switched to the corrected ones. However, I cannot expect colleagues/clients to this manually.
On the Intro-page I cannot hide the header, because then I get an error when replacing the text at the bookmark (replacing “Intro” by “Introduction”).
What am I doing wrong with odd/even headers/footers? Is there a way to make approach 1 work, so that I do not have to clutter up my template as in approach 2?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am trying to build a recto verso document with different odd and even headers and footers, based on a company template. I tried several approaches, but none works. I have made two reprex-templates (template1.docx and template2.docx) based on how our company template looks like. It is a two-sided document, hence the white pages. Basically there is a cover, the first real page contains an introduction (page numbering starts here), followed by a toc on page 3, after which the real text starts from page 5 onwards, with odd and even headers/footers. The last page contains our company logo and legal information. The following reprexcode generates the document with both templates. You can find the results that I get in reprex_template1_generated.docx and reprex_template2_generated.docx. The docs reprex_template1_expected.docx and reprex_template2_expected.docx are the outputs as I would wish them to be.
Reprex code:
Approach 1 uses template1.docx
This approach uses headers and footers which differ from section to section, by deselecting “Link to previous”. The option “Different Odd & Even Pages” has been selected in the template.
Things that go wrong:
Approach 2 uses template2.docx
This approach uses headers and footers which are the same on every page by selecting “Link to previous” for each new section. But because the headers and footers should not be visible on each page (for example the white back-pages), I had to hide them using a textbox. This is, however, an approach I’d rather not use …
Things that go wrong:
What am I doing wrong with odd/even headers/footers? Is there a way to make approach 1 work, so that I do not have to clutter up my template as in approach 2?
template1.docx
template2.docx
reprex_template1_generated.docx
reprex_template2_generated.docx
reprex_expected_output.docx
Beta Was this translation helpful? Give feedback.
All reactions