How to adjust HTML tables width to content in quarto documents?

This is probably a simple one but the correct search terms are eluding me, how to set the column width to adjust to content for HTML tables in quarto? specifically, gt tables.

In markdown, this was the default behavior but with quarto the table maximizes to take the full space, consider this simple example where you have a very small table.

---
title: "Test"
format:
  html:
    self-contained: true
knitr:
  opts_chunk: 
    echo: false
    warning: false
    message: false
editor: visual
---

```{r}
#| tbl-colwidths: false

library(dplyr)
library(gt)

iris %>% 
    count(Species) %>% 
    gt()
```

When executed interactively the table renders small on the Visual Editor, but when rendered, the table expands to the full page layout width.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

I cross-posted this on GitHub and found out this is a current deficiency of Quarto but I got a walkaround by using gt::as_raw_html()

1 Like