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

Add extra header second page and after in Tables that span multiple pages in PDF document #394

Open
ujtwr opened this issue Apr 22, 2022 · 3 comments
Labels
feature request pdf related to pdf output

Comments

@ujtwr
Copy link

ujtwr commented Apr 22, 2022

When outputting PDF, flextable uses latex's "longtable". longtable allows for separate headers for the first page and the second and subsequent pages. I want to add text like "(continued)" at the top of the header for the second and subsequent pages.
For this purpose,

I created the following function. Simply add text to the bottom of the latex source "\endfirsthead". It would be nice to be able to set any text, adjust font family, size, text alignment, etc. It might be nice if the footer could also be displayed on a page-by-page basis.

MyFunc <- function(x){
  tableNcol <- ncol_keys(x)
  
  if(!is.null(knitr::opts_knit$get("rmarkdown.pandoc.to"))){
    if(knitr::opts_knit$get("rmarkdown.pandoc.to") %in% c("beamer", "latex")) {
      flextable_to_rmd(x, print = FALSE) %>% 
        str_replace_all(
          fixed("\\endfirsthead"),
          fixed(str_glue("\\endfirsthead\n\n\\multicolumn{tableNcol}{{r}}{{(continued)}}\\\\", tableNcol=tableNcol))
        ) %>% 
        cat()
    }
  }else{
    return(x)
  }
}

If you use the following in a chunk, it will be rendered as is inline, and when knit, the latex source will be rewritten.

airquality %>% 
  slice(1:60) %>% 
  flextable() %>% 
  theme_booktabs() %>% 
  autofit() %>% 
  MyFunc()


@davidgohel
Copy link
Owner

Sorry for the delay

We will try, but no promise :)

In general, we are trying to add the same features for Word/PPTX/HTML/PDF but there it is a request for an exception for PDF only.

@MargaretSiple-NOAA
Copy link

MargaretSiple-NOAA commented Apr 6, 2023

I would also love to see this feature in the Word files generated with flextable. A header on the following page ("Table 1 continued"), footer on the first page ("Table 1 continues on following page") or similar would be really helpful for some of the reports I've been using flextable for. I will continue searching to see if this type of thing is already out there for the docx people.

@davidgohel
Copy link
Owner

Unfortunately this feature does not exist in MS Word.

@davidgohel davidgohel added pdf related to pdf output feature request labels Feb 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request pdf related to pdf output
Projects
None yet
Development

No branches or pull requests

3 participants