Skip to content

Commit

Permalink
Align group_tt columns with multicolumn for tabular theme
Browse files Browse the repository at this point in the history
  • Loading branch information
jsr-p committed Nov 10, 2024
1 parent 4be6e6b commit bb5f18c
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions R/group_tabularray.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,28 @@ group_tabularray_col <- function(x, j, ihead, ...) {
if (is.null(j)) {
return(x)
}

out <- strsplit(x@table_string, split = "\\n")[[1]]

header <- rep("", ncol(x))
for (idx in seq_along(j)) {
header[min(j[[idx]])] <- names(j)[idx]
if ((x@theme[[1]] == "default") && (x@output == "latex")) {
# Tabular theme; use `multicolumn` to center text
header <- paste(mapply(
function(name, x) {
sprintf(
"\\multicolumn{%s}{c}{%s}",
max(x) - min(x) + 1,
name
)
},
names(j), j
), collapse = " & ")
} else {
header <- rep("", ncol(x))
for (idx in seq_along(j)) {
header[min(j[[idx]])] <- names(j)[idx]
}
header <- paste(header, collapse = " & ")
}
header <- paste(header, collapse = " & ")

# \toprule -> \midrule
midr <- sapply(j, function(x) sprintf("\\cmidrule[lr]{%s-%s}", min(x), max(x)))
Expand Down

0 comments on commit bb5f18c

Please sign in to comment.