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

show footnotes every page (with partial solution) #858

Open
KJByron opened this issue Sep 9, 2024 · 1 comment
Open

show footnotes every page (with partial solution) #858

KJByron opened this issue Sep 9, 2024 · 1 comment

Comments

@KJByron
Copy link

KJByron commented Sep 9, 2024

I'm using

  • kbl with longtable and booktabs
  • kable_styling with latex_options
  • footnote with threeparttable
    to create a long table with footnotes for a pdf

I'd like the footnotes to show on every page
ideally there'd be an every_page boolean argument for footnote

looks like the change would go in footnote.R, in the section starting line 287
can't create a pull because I'm not sure where bottomrule_regexp comes from

here's a mre with a partial solution:

set up

knitr::opts_chunk$set(echo = TRUE)
library(kableExtra)

dat <- data.frame(
  A = LETTERS[rep(1:26, each = 2)],
  B = letters[rep(1:26, 2)],
  n = 0:51
)
names(dat)[3] <- paste0(names(dat)[3], "\\tnote{1}")

current

dat_kbl <- dat |>
  kbl(format = "latex", caption = "Caption",
    escape = FALSE, booktabs = TRUE, longtable = TRUE) |>
  kable_styling(
    latex_options = "repeat_header") |>
  footnote(
    number = c(
      "rows with n = 0 may be deleted in the final table"),
    threeparttable = TRUE)
dat_kbl

modification

dat_kbl_mod <- sub(pattern = "\n\\endfoot",
  replacement = "\n\\midrule\n\\insertTableNotes\n\\endfoot", x = dat_kbl,
  fixed = TRUE)
dat_kbl_mod
@dmurdoch
Copy link
Collaborator

dmurdoch commented Sep 9, 2024

The regexp comes from here:

bottomrule_regexp <- "(\\\\bottomrule(\\[[^]]*])?)"
. It is used in two places: where you saw it in footnote.R, and also here:
index_bottomrule <- grep(paste0("^", bottomrule_regexp, "$"), x)
.

Please do submit a PR, but be careful that both uses still work.

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