From 07d7ea72f85dc853590ccdacd6a1fc5e2bf61906 Mon Sep 17 00:00:00 2001 From: Bill Denney Date: Mon, 12 May 2025 09:34:39 -0400 Subject: [PATCH] Make variable labels span columns by default (fix #133) --- NEWS.md | 4 ++++ R/table1.R | 2 ++ 2 files changed, 6 insertions(+) diff --git a/NEWS.md b/NEWS.md index 6a41e26..e005f11 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# table1 development + +* Variable labels to span all cells by default (fix #133) + # table1 1.5 * Improvements to `kableExtra` output generated by `t1kable()`. diff --git a/R/table1.R b/R/table1.R index fa212cc..6af4032 100644 --- a/R/table1.R +++ b/R/table1.R @@ -1245,6 +1245,7 @@ t1flex <- function(x, tablefn=c("qflextable", "flextable", "regulartable"), ...) y <- as.data.frame(y, stringsAsFactors=F) y2 <- data.frame(x=paste0(c("", rep("\U{00A0}\U{00A0}", nrow(y) - 1)), rownames(y)), stringsAsFactors=F) y <- cbind(setNames(y2, rlh), y) + y[1,] <- y[1,1] # Setup for labels spanning columns y }) df <- do.call(rbind, z) @@ -1274,6 +1275,7 @@ t1flex <- function(x, tablefn=c("qflextable", "flextable", "regulartable"), ...) out <- flextable::align(out, j=2:(ncolumns+1), align="center", part="header") out <- flextable::bold(out, part="header") out <- flextable::bold(out, i=i, j=1) + out <- flextable::merge_h(out, i = i) # Make labels span columns if (!is.null(caption)) { out <- flextable::set_caption(out, caption=caption)