Fix the duplicated row bug in LaTeX table. Fix a bug introduced in #73. Change back to div for cell_spec
diff --git a/R/util.R b/R/util.R
index dc71524..f63e0c0 100644
--- a/R/util.R
+++ b/R/util.R
@@ -111,3 +111,26 @@
     "\\usepackage{threeparttable}"
   ))
 }
+
+# Fix duplicated rows in LaTeX tables
+fix_duplicated_rows_latex <- function(kable_input, table_info) {
+  # Since sub/string_replace start from beginning, we count unique value from
+  # behind.
+  rev_contents <- rev(table_info$contents)
+  dup_index <- rev(ave(seq_along(rev_contents), rev_contents,
+                       FUN = seq_along))
+  for (i in which(dup_index != 1)) {
+    dup_row <- table_info$contents[i]
+    empty_times <- dup_index[i] - 1
+    new_row <- str_replace(
+      dup_row, "&",
+      paste(c("&", rep("\\\\\\\\empty", empty_times)), collapse = ""))
+    kable_input <- str_replace(kable_input, dup_row, new_row)
+    table_info$contents[i] <- new_row
+  }
+  table_info$duplicated_rows <- FALSE
+  return(list(kable_input, table_info))
+}
+
+
+