Skip to content
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

How to show multiple lines in page header or footer? #43

Closed
DawnYe opened this issue Aug 23, 2021 · 4 comments
Closed

How to show multiple lines in page header or footer? #43

DawnYe opened this issue Aug 23, 2021 · 4 comments

Comments

@DawnYe
Copy link

DawnYe commented Aug 23, 2021

Is there a way to add multiple lines of words (or a empty underline) with different alignments in the page header and footer? Or is there a way to insert a table (with multiple lines or top/bottom border) in the page header or footer?

@elong0527
Copy link
Collaborator

Could you provide an example to illustrate what exactly you would like to achieve? (either in Word document as attachment or a screenshot)

@DawnYe
Copy link
Author

DawnYe commented Aug 24, 2021

Sorry for the inconvenience. Please see the screenshot below.

table_format

As you can see, the table page header and footer have multiple lines and they are in a table environment (one column and multiple rows) with a bottom border in the header and a top border in the footer. And in the header, the first line about page number is right aligned.

Thanks.

@elong0527
Copy link
Collaborator

Multiple line can be handled by provide a vector of text as input.

I will add feature to vectorize text alignment and other formatting argument in rtf_header and rtf_footer.

I am not sure why a borderline is required for header and footer. No plan to implement them at current stage.
But you can see how to do it by using some internal function in r2rtf.

library(r2rtf)
library(magrittr)

# Define a paragraph with different text justification
# ToDo: enable this feature in rtf_header and rtf_footer
header <- r2rtf:::rtf_paragraph(
              c("{Page \\pagenumber of \\pagefield}",
              "{text1}", 
              "{text2}"),
              justification = c("r", "l","l"), 
              space_before = 0, 
              space_after = 0
)

# Defin a dummy table for page header and page footer line 
line <- data.frame(x = "") %>% 
            rtf_page(border_first = "", border_last = "single") %>% 
            rtf_body(as_colheader = FALSE, 
                     border_left = "",
                     border_right = "", 
                     border_bottom = "", 
                     cell_height = 0.1) %>% 
            rtf_footnote(c("foot1", "foot2"), as_table = FALSE, text_font_size = 12) %>% 
            r2rtf:::rtf_encode_table(verbose = TRUE)
line$body <- gsub("\n", "", line$body, fixed = TRUE)

header <- paste(paste(header, collapse = ""), line$body)
footer <- paste0(line$body, line$footnote)

tbl <- head(iris) %>% 
          rtf_page_header(header) %>% 
          rtf_body() %>% 
          rtf_page_footer(footer)

x <- tbl %>% rtf_encode()
cat(x$body)

tbl %>% rtf_encode() %>% write_rtf("tmp.rtf")

@DawnYe
Copy link
Author

DawnYe commented Aug 25, 2021

This was very helpful. Thanks for the kindly reply. I'll close the issue page.

@DawnYe DawnYe closed this as completed Aug 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants