extra changes for footnote with threeparttable
diff --git a/R/footnote.R b/R/footnote.R
index 54929d0..77452ab 100644
--- a/R/footnote.R
+++ b/R/footnote.R
@@ -197,13 +197,10 @@
table_info <- magic_mirror(kable_input)
out <- enc2utf8(as.character(kable_input))
- # if (table_info$tabular == "longtable" & threeparttable == TRUE) {
- # threeparttable <- FALSE
- # warning("threeparttable does not support longtable.")
- # }
footnote_text <- latex_tfoot_maker(footnote_table, footnote_as_chunk,
table_info$ncol, threeparttable)
if (threeparttable) {
+ if (table_info$tabular %in% c("longtable", "longtabu") ) {
out <- sub(paste0("\\\\begin\\{", table_info$tabular, "\\}"),
paste0("\\\\begin{ThreePartTable}\n\\\\begin{TableNotes}",
ifelse(footnote_as_chunk, "[para]", ""),
@@ -211,24 +208,43 @@
"\n\\\\end{TableNotes}\n\\\\begin{",
table_info$tabular, "}"),
out)
- out <- sub(table_info$end_tabular,
- paste0("\\\\end{", table_info$tabular,
- "}\n\\\\end{ThreePartTable}"),
- out)
- if (table_info$booktabs) {
- out <- sub("\\\\bottomrule", "\\\\bottomrule\n\\\\insertTableNotes", out)
+ out <- sub(paste0("\\\\end\\{",table_info$tabular, "\\}"),
+ paste0("\\\\end{", table_info$tabular,
+ "}\n\\\\end{ThreePartTable}"),
+ out)
+ if (table_info$booktabs) {
+ out <- sub("\\\\bottomrule", "\\\\bottomrule\n\\\\insertTableNotes", out)
+ } else {
+ out <- sub("\\\\hline\n\\\\end\\{longtable\\}",
+ "\\\\hline\n\\\\insertTableNotes\n\\\\end\\{longtable\\}",
+ out)
+ }
} else {
- out <- sub("\\\\hline\n\\\\end\\{longtable\\}",
- "\\\\hline\n\\\\insertTableNotes\n\\\\end\\{longtable\\}",
+ if (table_info$tabular == "tabu") {
+ stop("Please use `longtable = T` in your kable function. ",
+ "Full width threeparttable only works with longtable.")
+ }
+ out <- sub(paste0("\\\\begin\\{", table_info$tabular, "\\}"),
+ paste0("\\\\begin{threeparttable}\n\\\\begin{",
+ table_info$tabular, "}"),
+ out)
+ out <- sub(table_info$end_tabular,
+ paste0("\\\\end{", table_info$tabular,
+ "}\n\\\\begin{tablenotes}",
+ ifelse(footnote_as_chunk, "[para]", ""),
+ "\n\\\\small\n", footnote_text,
+ "\n\\\\end{tablenotes}\n\\\\end{threeparttable}"),
out)
}
- } else if (table_info$booktabs) {
- out <- sub("\\\\bottomrule",
- paste0("\\\\bottomrule\n", footnote_text), out)
} else {
- out <- sub(table_info$end_tabular,
- paste0(footnote_text, "\n\\\\end{", table_info$tabular, "}"),
- out)
+ if (table_info$booktabs) {
+ out <- sub("\\\\bottomrule",
+ paste0("\\\\bottomrule\n", footnote_text), out)
+ } else {
+ out <- sub(table_info$end_tabular,
+ paste0(footnote_text, "\n\\\\end{", table_info$tabular, "}"),
+ out)
+ }
}
out <- structure(out, format = "latex", class = "knitr_kable")
diff --git a/R/zzz.R b/R/zzz.R
index 38c06b0..a444d34 100644
--- a/R/zzz.R
+++ b/R/zzz.R
@@ -11,6 +11,7 @@
usepackage_latex("colortbl")
usepackage_latex("pdflscape")
usepackage_latex("tabu")
+ usepackage_latex("threeparttable")
usepackage_latex("threeparttablex")
usepackage_latex("ulem", "normalem")
}