gt icon indicating copy to clipboard operation
gt copied to clipboard

`tab_spanner()` does not work as intended when output format is docx

Open dan-cloney opened this issue 1 year ago • 1 comments

Description

when rendered via Quarto with output format as docx, tab_spanner does not work as intended. The spanner column is added to the appropriate row, above the columns specified, however the other columns now are on the same row as the spanner column. Tables render correctly when the format is pdf or html.

Reproducible example

---
title: "quarto gt"
format: docx
---

## Quarto

A table @tbl-gt.

```{r}
#| label: tbl-gt
#| tbl-cap: A Caption
#| echo: false

library(gt)

mtcars |> 
  head() |>
  gt() |>  
  tab_spanner(
    label = "performance",
    columns = c(
      mpg, cyl, disp
      )
  ) 
```

See output docx file: quarto_gt.docx

Expected result

In this case, the expectation is that a row "performance" should appear in the first row, spanning the columns mpg, cyl, and disp. The remaining columns should be on the same row as mpg, cyl, and disp.

See output pdf file: quarto_gt.pdf See output html:

performance hp drat wt qsec vs am gear carb
mpg cyl disp
21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
18.1 6 225 105 2.76 3.460 20.22 1 0 3 1

Session info

> packageVersion("gt")
[1] ‘0.6.0.9000’

> sessionInfo()
R version 4.2.1 (2022-06-23)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Monterey 12.4

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

loaded via a namespace (and not attached):
 [1] compiler_4.2.1   fastmap_1.1.0    cli_3.3.0       
 [4] htmltools_0.5.3  tools_4.2.1      rstudioapi_0.13 
 [7] yaml_2.3.5       rmarkdown_2.14.2 knitr_1.39      
[10] xfun_0.31        digest_0.6.29    rlang_1.0.4     
[13] evaluate_0.15 
% quarto --version       
1.0.37
% quarto pandoc --version
pandoc 2.18

dan-cloney avatar Jul 28 '22 02:07 dan-cloney

Ah I see. Yeah, this is a stylistic break from the other formats for sure. We'll try to work on this soon but seeing as there are some critical bugs reported lately, it might take a bit more time to begin on this one.

rich-iannone avatar Aug 16 '22 15:08 rich-iannone

We've decided that merged cells in Word output, non-spanner column labels is not a priority right now. We may get to this in the future, but we're closing this for now.

rich-iannone avatar Nov 03 '22 19:11 rich-iannone

@rich-iannone I noticed that cross-reference was broken in the above example. Here is a screenshot from docx.

I use quarto 1.2.269 and gt 0.8.0

XiangyunHuang avatar Nov 20 '22 00:11 XiangyunHuang

Here is my sessioninfo

> packageVersion('gt')
[1] ‘0.8.0’
> sessionInfo()
R version 4.2.2 (2022-10-31)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Ventura 13.0.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] compiler_4.2.2  fastmap_1.1.0   cli_3.4.1       htmltools_0.5.3 tools_4.2.2    
 [6] rstudioapi_0.14 yaml_2.3.6      rmarkdown_2.18  knitr_1.41      xfun_0.35      
[11] digest_0.6.30   rlang_1.0.6     evaluate_0.18

XiangyunHuang avatar Nov 20 '22 00:11 XiangyunHuang