Give people ability to customize title format in footnote
diff --git a/R/footnote.R b/R/footnote.R
index a7e2aa2..5d1e363 100644
--- a/R/footnote.R
+++ b/R/footnote.R
@@ -29,6 +29,8 @@
#' @param number_title Section header for number footnotes. Default is "".
#' @param alphabet_title Section header for alphabet footnotes. Default is "".
#' @param symbol_title Section header for symbol footnotes. Default is "".
+#' @param title_format Choose from "italic"(default), "bold" and "underline".
+#' Multiple options are possible.
#'
#'
#' @examples dt <- mtcars[1:5, 1:5]
@@ -48,7 +50,8 @@
general_title = "Note: ",
number_title = "",
alphabet_title = "",
- symbol_title = ""
+ symbol_title = "",
+ title_format = "italic"
) {
kable_format <- attr(kable_input, "format")
if (!kable_format %in% c("html", "latex")) {
@@ -90,6 +93,10 @@
footnote_titles <- lapply(footnote_titles, linebreak)
}
}
+ title_format <- match.arg(title_format, c("italic", "bold", "underline"),
+ several.ok = TRUE)
+ footnote_titles <- lapply(footnote_titles, footnote_title_format,
+ kable_format, title_format)
footnote_table <- footnote_table_maker(
kable_format, footnote_titles, footnote_contents
)
@@ -102,6 +109,36 @@
}
}
+footnote_title_format <- function(x, format, title_format) {
+ if (x == "") return(x)
+ if (format == "html") {
+ title_style <- ""
+ if ("italic" %in% title_format) {
+ title_style <- paste0(title_style, "font-style: italic;")
+ }
+ if ("bold" %in% title_format) {
+ title_style <- paste0(title_style, "font-weight: bold;")
+ }
+ if ("underline" %in% title_format) {
+ title_style <- paste0(title_style, "text-decoration: underline;")
+ }
+ return(paste0(
+ '<span style="', title_style, '">', x, '</span>'
+ ))
+ } else {
+ if ("italic" %in% title_format) {
+ x <- paste0("\\\\textit\\{", x, "\\}")
+ }
+ if ("bold" %in% title_format) {
+ x <- paste0("\\\\textbf\\{", x, "\\}")
+ }
+ if ("underline" %in% title_format) {
+ x <- paste0("\\\\underline\\{", x, "\\}")
+ }
+ return(x)
+ }
+}
+
footnote_table_maker <- function(format, footnote_titles, footnote_contents) {
number_index <- read.csv(system.file("symbol_index.csv",
package = "kableExtra"))
@@ -176,7 +213,7 @@
paste0('<sup>', x[1], '</sup> ', x[2])
})
if (ft_title != "") {
- title_text <- paste0('<em>', ft_title, '</em>')
+ title_text <- ft_title
footnote_text <- c(title_text, footnote_text)
}
if (!ft_chunk) {
@@ -285,7 +322,7 @@
}
})
if (ft_title != "") {
- title_text <- paste0('\\\\textit{', ft_title, '} ')
+ title_text <- ft_title
footnote_text <- c(title_text, footnote_text)
}
if (!ft_chunk) {
@@ -311,7 +348,7 @@
}
})
if (ft_title != "") {
- title_text <- paste0('\\\\item \\\\textit{', ft_title, '} ')
+ title_text <- paste0('\\\\item ', ft_title, ' ')
footnote_text <- c(title_text, footnote_text)
}
footnote_text <- paste0(footnote_text, collapse = "\n")
diff --git a/docs/awesome_table_in_pdf.pdf b/docs/awesome_table_in_pdf.pdf
index 3306a65..1277d4c 100644
--- a/docs/awesome_table_in_pdf.pdf
+++ b/docs/awesome_table_in_pdf.pdf
Binary files differ
diff --git a/tests/visual_tests/footnote_latex.Rmd b/tests/visual_tests/footnote_latex.Rmd
index 65bef09..7771153 100644
--- a/tests/visual_tests/footnote_latex.Rmd
+++ b/tests/visual_tests/footnote_latex.Rmd
@@ -20,7 +20,7 @@
booktabs = T, escape = F, longtable = T) %>%
footnote(NULL, c("number 1; ", "number 2. "), c("a 1; ", "a 2."), c("s 1; ", "s 2."),
number_title = "special: ", alphabet_title = "abc: ",
- footnote_as_chunk = T)
+ footnote_as_chunk = T, title_format = c("italic", "bold"))
```
```{r}
@@ -28,7 +28,7 @@
kable("latex", booktabs = T, caption = "hi") %>%
kable_styling(position = "left") %>%
footnote(number = c("For this particular use (i.e. a general note) the comments above are adequate. For proper footnotes in tables you should probably use the threeparttable package. You should also probably be using the booktabs package. See this answer to this question", "Note 2"),
- number_title = "Note: ", threeparttable = T, footnote_as_chunk = T)
+ number_title = "Note: ", threeparttable = T, footnote_as_chunk = T, title_format = c("italic", "bold"))
```
```{r}