Fix #331
diff --git a/R/group_rows.R b/R/group_rows.R
index f5b4864..746fb1a 100644
--- a/R/group_rows.R
+++ b/R/group_rows.R
@@ -214,32 +214,29 @@
}
+ rowtext <- table_info$contents[start_row + table_info$position_offset]
if (table_info$booktabs) {
- rowtext <- table_info$contents[start_row + table_info$position_offset]
- pre_rowtext <- paste0(
- "\\\\addlinespace[", gap_space, "]\n",
- ifelse(hline_before,"\\\\hline\n", ""),
- "\\\\multicolumn{", ifelse(is.null(colnum),
- table_info$ncol,
- colnum),
- "}{", latex_align, "}{", group_label,
- "}\\\\\\\\\n", ifelse(hline_after, "\\\\hline\n", '')
- )
+ pre_rowtext <- paste0("\\\\addlinespace[", gap_space, "]\n")
} else {
- rowtext <- table_info$contents[start_row + 1]
- rowtext <- paste0("\\\\hline\n", rowtext)
- pre_rowtext <- paste0(
- "\\\\hline\n\\\\multicolumn{", table_info$ncol, "}{", latex_align,"}{",
- group_label, "}\\\\\\\\\n"
- )
+ pre_rowtext <- ''
+ hline_after <- TRUE
}
+ pre_rowtext <- paste0(
+ pre_rowtext,
+ ifelse(hline_before,"\\\\hline\n", ""),
+ "\\\\multicolumn{", ifelse(is.null(colnum),
+ table_info$ncol,
+ colnum),
+ "}{", latex_align,"}{", group_label,
+ "}\\\\\\\\\n", ifelse(hline_after, "\\\\hline\n", '')
+ )
if(!is.null(extra_latex_after)){
pre_rowtext <- paste0(pre_rowtext,
regex_escape(extra_latex_after, double_backslash = TRUE))
}
new_rowtext <- paste0(pre_rowtext, rowtext)
if (start_row + 1 == table_info$nrow &
- !is.null(table_info$repeat_header_latex)) {
+ !is.null(table_info$repeat_header_latex) & table_info$booktabs) {
out <- sub(paste0(rowtext, "\\\\\\\\\\*\n"),
paste0(new_rowtext, "\\\\\\\\\\*\n"),
out)
diff --git a/docs/awesome_table_in_pdf.Rmd b/docs/awesome_table_in_pdf.Rmd
index 2e79da6..f1db135 100644
--- a/docs/awesome_table_in_pdf.Rmd
+++ b/docs/awesome_table_in_pdf.Rmd
@@ -565,7 +565,7 @@
The latest version of [`tables`](https://CRAN.R-project.org/package=tables) comes with a `toKable()` function, which is compatiable with functions in `kableExtra` (>=0.9.0).
## `xtable`
-For `xtable` users, if you want to use `kableExtra` functions on that, check out this `xtable2kable()` function shipped with kableExtra 1.0.
+For `xtable` users, if you want to use `kableExtra` functions on that, check out this `xtable2kable()` function shipped with kableExtra 1.0. I personally have been using this function to place table caption below tables and solve some tricky case when I use `tufte_handout`.
```{r, eval=F}
# Not evaluating
diff --git a/docs/awesome_table_in_pdf.pdf b/docs/awesome_table_in_pdf.pdf
index eabc76b..ed7eb13 100644
--- a/docs/awesome_table_in_pdf.pdf
+++ b/docs/awesome_table_in_pdf.pdf
Binary files differ
diff --git a/tests/visual_tests/duplicated rows.Rmd b/tests/visual_tests/duplicated rows.Rmd
new file mode 100644
index 0000000..aec300b
--- /dev/null
+++ b/tests/visual_tests/duplicated rows.Rmd
@@ -0,0 +1,15 @@
+---
+title: "duplicated rows"
+output: pdf_document
+---
+
+```{r}
+library(dplyr)
+library(kableExtra)
+
+tbl1 <- bind_rows(mtcars, mtcars, mtcars, mtcars)
+
+kable(tbl1, longtable = T, row.names = 1:128) %>%
+ pack_rows(index = c("g1" = 3, "g2" = 6, "g3" = 5, "g4" = 5, "g1" = 3, "g2" = 6, "g3" = 5, "g4" = 5,
+ "g1" = 3, "g2" = 6, "g3" = 5, "g4" = 5))
+```
diff --git a/tests/visual_tests/indent_and_row_group.Rmd b/tests/visual_tests/indent_and_row_group.Rmd
index b9e35bd..cb2a75f 100644
--- a/tests/visual_tests/indent_and_row_group.Rmd
+++ b/tests/visual_tests/indent_and_row_group.Rmd
@@ -27,6 +27,6 @@
mtcars$wt[i] <- paste0(mtcars$wt[i], " &")
mtcars$mpg[i] <- paste0(mtcars$mpg[i], "%")
}
-kable(head(iris, n = 20), "latex", caption = "test", booktabs = T,
+kable(head(mtcars, n = 20), "latex", caption = "test", booktabs = T,
align = c("ccccc"))
```