Merge pull request #50 from robshep/master
Add option for using float package with [H] float specifier
diff --git a/DESCRIPTION b/DESCRIPTION
index 48dc40e..c1851fd 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,7 +1,7 @@
Package: kableExtra
Type: Package
Title: Construct Complex Table with 'kable' and Pipe Syntax
-Version: 0.4.0.9000
+Version: 0.4.0.9001
Authors@R: c(
person('Hao', 'Zhu', email = 'haozhu233@gmail.com', role = c('aut', 'cre')),
person('Will', 'Beasley', email = 'wibeasley@hotmail.com', role = 'ctb'),
diff --git a/R/kable_styling.R b/R/kable_styling.R
index a33f820..c957f5a 100644
--- a/R/kable_styling.R
+++ b/R/kable_styling.R
@@ -12,12 +12,13 @@
#' `bordered`, `hover`, `condensed` and `responsive`.
#' @param latex_options A character vector for LaTeX table options. Please see
#' package vignette for more information. Possible options include
-#' `basic`, `striped`, `hold_position`, `scale_down` & `repeat_header`.
+#' `basic`, `striped`, `hold_position`, `HOLD_position`, `scale_down` & `repeat_header`.
#' `striped` will add alternative row colors to the table. It will imports
#' `LaTeX` package `xcolor` if enabled. `hold_position` will "hold" the floating
#' table to the exact position. It is useful when the `LaTeX` table is contained
#' in a `table` environment after you specified captions in `kable()`. It will
#' force the table to stay in the position where it was created in the document.
+#' A stronger version: `HOLD_position` requires the `float` package and specifies [H].
#' `scale_down` is useful for super wide table. It will automatically adjust
#' the table to page width. `repeat_header` in only meaningful in a longtable
#' environment. It will let the header row repeat on every page in that long
@@ -180,7 +181,7 @@
latex_options <- match.arg(
latex_options,
- c("basic", "striped", "hold_position", "scale_down", "repeat_header"),
+ c("basic", "striped", "hold_position", "HOLD_position", "scale_down", "repeat_header"),
several.ok = T
)
@@ -199,6 +200,11 @@
out <- styling_latex_hold_position(out)
}
+ # HOLD_position is only meaningful in a table environment
+ if ("HOLD_position" %in% latex_options & table_info$table_env) {
+ out <- styling_latex_HOLD_position(out)
+ }
+
if ("scale_down" %in% latex_options) {
out <- styling_latex_scale_down(out, table_info)
}
@@ -258,6 +264,10 @@
sub("\\\\begin\\{table\\}", "\\\\begin\\{table\\}[!h]", x)
}
+styling_latex_HOLD_position <- function(x) {
+ sub("\\\\begin\\{table\\}", "\\\\begin\\{table\\}[H]", x)
+}
+
styling_latex_scale_down <- function(x, table_info) {
# You cannot put longtable in a resizebox
# http://tex.stackexchange.com/questions/83457/how-to-resize-or-scale-a-longtable-revised