rstudio/gt

Setting column widths isn't honoured when rendering with a html-document with Quarto

snhansen opened this issue · 1 comments

Description

On the development version of gt, col_widths() isn't working when rendering a html-document with Quarto (v. 1.6.4).

Reproducible example

---
format: html
---

```{r}
mtcars[1:4, 1:4] |>
  gt::gt() |>
  gt::cols_width(
    "mpg" ~ px(150),
    c("cyl", "disp", "hp") ~ px(50)
  )
```

Expected result

image

Actual result

image

Session info

R version 4.4.0 (2024-04-24 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 10 x64 (build 19045)

Matrix products: default


locale:
[1] LC_COLLATE=Danish_Denmark.utf8     LC_CTYPE=Danish_Denmark.utf8      
[3] LC_MONETARY=Danish_Denmark.utf8    LC_NUMERIC=C                      
[5] LC_TIME=English_United States.1252

time zone: Europe/Copenhagen
tzcode source: internal

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

loaded via a namespace (and not attached):
 [1] vctrs_0.6.5       cli_3.6.3         gt_0.11.0.9000    knitr_1.48       
 [5] rlang_1.1.4       xfun_0.47         generics_0.1.3    jsonlite_1.8.8   
 [9] glue_1.7.0        htmltools_0.5.8.1 sass_0.4.9        fansi_1.0.6      
[13] rmarkdown_2.28    evaluate_0.24.0   tibble_3.2.1      fastmap_1.2.0    
[17] yaml_2.3.10       lifecycle_1.0.4   compiler_4.4.0    dplyr_1.1.4      
[21] htmlwidgets_1.6.4 pkgconfig_2.0.3   digest_0.6.37     R6_2.5.1         
[25] tidyselect_1.2.1  utf8_1.2.4        pillar_1.9.0      magrittr_2.0.3   
[29] tools_4.4.0       withr_3.0.1       xml2_1.3.6     

Hi, this is because Quarto processes htnl tables, see also #1183

https://quarto.org/docs/authoring/tables.html#disabling-quarto-table-processing

You can use this for example (It is also available as an argument of tab options and can be set to the document as a whole

---
format: html
---

```{r}
#| html-table-processing: none
mtcars[1:4, 1:4] |>
  gt::gt() |>
  gt::cols_width(
    "mpg" ~ px(150),
    c("cyl", "disp", "hp") ~ px(50)
  )
```