great-tables icon indicating copy to clipboard operation
great-tables copied to clipboard

Wide columns in latex output with spans

Open malcolmbarrett opened this issue 7 months ago • 0 comments

Prework

Description

When using exporting a GT to PDF, I get unusual output. The base problem is that the formatting is off with a span: the first column is very wide.

Reproducible example

Here is a quarto file

---
format: pdf
---

Example using the `gtcars` dataset.

```{python}
from great_tables import GT
from great_tables.data import gtcars
import polars as pl

gtcars_pl = (
    pl.from_pandas(gtcars)
    .select(["mfr", "model", "hp", "trq", "mpg_c", "msrp"])
)

gt_tbl = (
    GT(
        gtcars[["mfr", "model", "hp", "trq", "msrp"]].head(5),
    )
    .tab_stub(rowname_col="mfr", groupname_col="model")
    .tab_spanner(
        label="Performance",
        columns=["hp", "trq"]
    )
)

gt_tbl
```

And the result is

Image

When I use gt_tbl.as_latex() here, I get an error.

Relatedly, I seem to be getting different output based on if I end a cell with a gt object (implicitly printing/showing it) vs. as_latex(). Try it with this example without tab_stub() and you will see what I mean.

Expected result

The table should not float off the page, and the first column should not be so wide.

Development environment

  • Operating System: Mac

Here's my uv toml:

[project]
name = "gt-reprex"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.13"
dependencies = [
    "great-tables>=0.17.0",
    "jupyter>=1.1.1",
    "pandas>=2.2.3",
    "polars>=1.26.0",
]

malcolmbarrett avatar Apr 04 '25 18:04 malcolmbarrett