Skip to content

Commit

Permalink
issue #362 duplicate group indices in latex
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Nov 4, 2024
1 parent f1daecf commit ec6f100
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/group_tabularray.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ group_tabularray_col <- function(x, j, ihead, ...) {
out <- strsplit(x@table_string, split = "\\n")[[1]]

header <- rep("", ncol(x))
for (n in names(j)) {
header[min(j[[n]])] <- n
for (idx in seq_along(j)) {
header[min(j[[idx]])] <- names(j)[idx]
}
header <- paste(header, collapse = " & ")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
\begin{table}
\centering
\begin{tblr}[ %% tabularray outer open
] %% tabularray outer close
{ %% tabularray inner open
colspec={Q[]Q[]Q[]Q[]},
cell{1}{1}={c=2,}{halign=c,},
cell{1}{3}={c=2,}{halign=c,},
} %% tabularray inner close
\toprule
a & & a & \\ \cmidrule[lr]{1-2}\cmidrule[lr]{3-4}
sub1 & sub2 & sub1 & sub2 \\ \midrule %% TinyTableHeader
1 & 2 & 3 & 4 \\
\bottomrule
\end{tblr}
\end{table}
10 changes: 10 additions & 0 deletions inst/tinytest/test-group_tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ tab <- tt(x) |>
group_tt(j = list("a" = 2:3, "b" = 4:5)) |>
group_tt(j = list("c" = 1:2, "d" = 3:5)) |>
group_tt(j = list("e" = 1:3, "f" = 4))
tab@output <- "latex"
expect_snapshot_print(tab, label = "group_tt-3level.tex")
options(tinytable_print_output = NULL)

Expand Down Expand Up @@ -103,3 +104,12 @@ for (o in c("latex", "typst", "markdown", "html")) {

options(tinytable_print_output = NULL)
}


# Issue #362: group_tt with duplicate column group labels in latex
tab <- data.frame(sub1 = 1, sub2 = 2, sub1 = 3, sub2 = 4, check.names = FALSE) |>
tt() |>
group_tt(j = list(a = 1:2, a = 3:4))
tab@output <- "latex"
expect_snapshot_print(tab, "group_tt-issue362_duplicate_colum_labels.tex")

0 comments on commit ec6f100

Please sign in to comment.