Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Report: tbl_stack() header alignment when exported to pdf via as_kable_extra() with \n in modify_header() #1326

Closed
shannonpileggi opened this issue Aug 25, 2022 · 0 comments · Fixed by #1333
Milestone

Comments

@shannonpileggi
Copy link
Collaborator

In individual tbl_summary() outputs utilizing modify_header() with \n line breaks, column headers render to pdf as expected (centered).

However, when combining tables via tbl_stack(), outputs utilizing modify_header() with \n line breaks, column headers render to pdf as trt 1 left justified and trt 2 centered.

Here is the output:

image

Here is the source .Rmd:


---
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(tidyverse)
library(gtsummary)
t1 <- trial |> 
  select(trt, age) |> 
  tbl_summary(
    by = trt
  )

Table 1

t1 |> 
  modify_header(
    all_stat_cols() ~ "**{level}**\nN = {n}"
  ) |> 
  as_kable_extra()
t2 <- trial |> 
  select(trt, grade) |> 
  tbl_summary(
    by = trt
  )

Table 2

t2 |> 
  modify_header(
    all_stat_cols() ~ "**{level}**\nN = {n}"
  ) |> 
  as_kable_extra()

Stack Table 1 & Table 2, then modify header

tbl_stack(list(t1, t2)) |> 
  modify_header(
    all_stat_cols() ~ "**{level}**\nN = {n}"
  ) |> 
  as_kable_extra()

Modify header in Table 1, then stack

t1_modify <- t1 |> 
  modify_header(
    all_stat_cols() ~ "**{level}**\nN = {n}"
  )
tbl_stack(
  list(t1_modify, t2),
  quiet = TRUE
  ) |> 
  as_kable_extra()
@ddsjoberg ddsjoberg added this to the v1.6.2 milestone Aug 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants