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: spanner wrong in docx rendering #2109

Closed
raffaem opened this issue Dec 20, 2024 · 4 comments
Closed

Bug Report: spanner wrong in docx rendering #2109

raffaem opened this issue Dec 20, 2024 · 4 comments

Comments

@raffaem
Copy link

raffaem commented Dec 20, 2024

Consider the following Quarto MWE:

---
title: "Title"
format:
  pdf: default
  docx: default
---

```{r}
#| label: tbl-bug
#| echo: false
#| output: true
mod1 <- gtsummary::tbl_regression(lm(mpg ~ wt, data = mtcars))
mod2 <- gtsummary::tbl_regression(lm(mpg ~ wt+gear, data = mtcars))
spanner <- c("Model 1", "Model2")
gtsummary::tbl_merge(list(mod1, mod2), tab_spanner=spanner)
```

This is how is rendered in PDF (good):

Screenshot_20241220_183157

This is how it is rendered in docx.
The spanner is wrong, as the first header covers only one column instead of 3:

Screenshot_20241220_183242

@ddsjoberg
Copy link
Owner

Thanks for the post @raffaem !

If you don't include the #| label: tbl-bug tag, the table renders properly. This looks like a Quarto+gt bug to me?

---
title: "Untitled"
format: docx
---

## Quarto

```{r}
library(gtsummary)
packageVersion("gtsummary")

list(
  tbl_regression(lm(mpg ~ wt, data = mtcars)),
  tbl_regression(lm(mpg ~ wt+gear, data = mtcars))
) |> 
  tbl_merge(tab_spanner=c("Model 1", "Model2"))
```

image

@raffaem
Copy link
Author

raffaem commented Dec 20, 2024

So how can I get the gt code to reproduce that table, so I can report it upstream?

@ddsjoberg
Copy link
Owner

You can use as_gt(return_calls = TRUE), but that will give you a lot of extra code. Probably best to just use a small dummy example and add two spanning headers with gt::tab_spanner()

list(
  tbl_regression(lm(mpg ~ wt, data = mtcars)),
  tbl_regression(lm(mpg ~ wt+gear, data = mtcars))
) |> 
  tbl_merge(tab_spanner=c("Model 1", "Model2")) |> 
  as_gt(return_calls = TRUE)

@raffaem
Copy link
Author

raffaem commented Dec 21, 2024

rstudio/gt#1898

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

No branches or pull requests

2 participants