Skip to content

Adding tbl-colwidths as a label at the start of Python code cells no longer sets the column width of Markdown tables #9200

@carstrb

Description

@carstrb

Bug description

In v1.3.450 of quarto, Using labels at the top of code cells to specify table attributes such as tbl-colwidths allowed for per-table formatting when generating a PDF. However, the latest version of quarto (v1.4.551) seems to no longer to adhere to this command, and what results is a table that overruns the margins/boundary of the page that it is rendered on.

Steps to reproduce

The document below renders a simple table using data from mt-cars

---
format: pdf
echo: false
---

```{python}
#| tbl-colwidths: [20,10,15,10,15,15,15,15,15,15,15,10]

import pandas as pd
from IPython.display import Markdown
from tabulate import tabulate

df = pd.read_csv('https://gist.githubusercontent.com/ZeccaLehn/4e06d2575eb9589dbe8c365d61cb056c/raw/64f1660f38ef523b2a1a13be77b002b98665cdfe/mtcars.csv')

df.columns = [
    "Car Name",
    "Fuel Cons. (mpg)",
    "# Cylinders",
    "Displ. (cu.in.)",
    "Gross HP",
    "Rear axle ratio",
    "Weight (1000 lbs)",
    "1/4 mile time",
    "Engine",
    "Trans.",
    "# forward gears",
    "# carburetors",
]

Markdown(
    tabulate(
        df,
        headers="keys",
        showindex=False,
    )
)
```

To run, you'll need to copy the above contents into a .qmd file, and ensure the Python packages below have been installed. The command I use to render is quarto render <DOCUMENT_NAME.qmd>

The packages required to render this document as a pdf are as follows:

jupyter==1.0.0
pandas==2.2.1
ipython==8.22.2
tabulate==0.9.0

Expected behavior

A table that has been given tbl-colwidths arguments should remain within the margins of the page, with multi-line/wrapped headers based on the specified width of its respective column. See the following output below:

Screenshot 2024-03-26 144725

Actual behavior

In the case of quarto: v1.4.551, there is no formatting applied to the columns of the table, and so the result is a table that spills outside of the page right margin:
Screenshot 2024-03-26 145255

Your environment

  • IDE: VSCode [WSL: Ubuntu]: 1.87.2

  • Base OS: Windows 11 Home

  • Version: 23H2

  • OS Build: 22631.3296

  • WSL Distribution: Ubuntu 22.04.4 LTS

  • Release: 22.04

  • Codename: jammy

Quarto check output

Quarto 1.4.551
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.11: OK
      Dart Sass version 1.69.5: OK
      Deno version 1.37.2: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.4.551
      Path: /opt/quarto/bin

[✓] Checking tools....................OK
      TinyTeX: v2024.03.13
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Using: TinyTex
      Path: /home/carson/.TinyTeX/bin/x86_64-linux
      Version: 2024

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.12.2
      Path: /home/carson/Code/Playground/table_demo/quarto-table-demo/.venv/bin/python3
      Jupyter: 5.7.2
      Kernels: python3

[✓] Checking Jupyter engine render....OK

[✓] Checking R installation...........(None)

      Unable to locate an installed version of R.
      Install R from https://cloud.r-project.org/

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingregressionFunctionality that used to work but now is broken.tablesIssues with Tables including the gt integration

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions