davidgohel / flextable

table farming
https://ardata-fr.github.io/flextable-book/
565 stars 82 forks source link

Page breaks resulting in open borders when rendering as quarto PDF book #569

Open jonpeake opened 1 year ago

jonpeake commented 1 year ago

Unfortunately I can't seem to reproduce as a minimal example as there are a lot of moving parts, but I'm working on a quarto book and have a few long tables that break across multiple pages. Occasionally when I render to PDF, I get a break in a table prior to the inner border, rather than after the inner border. I've tried changing the size of the cells, switching from border_inner to hline and vline, changing font size, and it still happens consistently in at least a couple spots (see screenshot below for example). Any ideas as to what might be causing this?

  App2_ft <- data %>%
    filter(!Species %in% c("Effort")) %>%
    mutate_if(is.character, str_trim) %>%
    flextable(col_keys = colnames(data)[!str_detect(colnames(data),'spp')]) %>%
    set_table_properties(opts_pdf = list(caption_repeat = FALSE)) %>%
    compose(j = 'Species', value = as_paragraph(as_i(Species), ' ',spp)) %>%
    set_header_df(
      mapping = TB_App2_header,
      key = "col_keys"
    ) %>%
    merge_v(part = "header") %>%
    merge_at(i = 1, j = 2:(dim(data)[2]-2), part = "header") %>%
    #add  borders
    border_inner(part = "all", fp_border(color = "black", width = 1)) %>%
    border_outer(part = "all", fp_border(color = "black", width = 1)) %>%
    fontsize(part = "all", size = 7) %>%
    bold(bold = TRUE, part = "footer") %>%
    align(j = 2:dim(data)[2], align = "right", part = "footer") %>%
    #make the entire header row bold
    bold(bold = TRUE, part = "header") %>%
    #make totals and selecteds bold
    bold(bold = TRUE, i = bold_rows, part = 'body') %>%
    #text alignments
    align(align = "center", part = "header") %>%
    width(j = 1, width = 1.5) %>%
    width(j = 2:(dim(data)[2]-1), width = 0.45) %>%
    #align all numbers to the right
    align(j = 2:(dim(data)[2]-1), align = "right", part = "body") %>%
    align(j = 1, align = "left", part = "body") %>%
    set_table_properties(layout = "fixed", width = 1) %>%
    #to fix the right-alignment between the body and footer, include some white space padding
    padding(padding.right = 2, j = 2:dim(data)[2]-1, part = 'body') %>%
    #increase row height (specified in inches)
    height(height = 0.25, part = "header") %>%
    height(height = 0.25, part = "body") %>%
    height(height = 0.25, part = "footer") %>%
    #need hrule to actually make the above heights apply to the rows when rendered
    hrule(rule = "at least", part = "all") %>%
    #add bottom line of the footer and header
    hline_top(border = fp_border(color = "black", width = 2), part = "footer") %>%
    hline_bottom(border = fp_border(color = "black", width = 2), part = "header")  %>%
    fix_border_issues() %>%
    add_footer_lines("Effort, or total number of hauls, is labeled 'E'. Taxa are arranged alphabetically. Selected taxa are highlighted in bold.")

image