PgBiel / typst-tablex

More powerful and customizable tables in Typst
MIT License
370 stars 12 forks source link

Explicit use of `x` (`y`) in `cellx(x: ...)` causes table rows to be uneven when `rows` parameter is set #97

Closed Andrew15-5 closed 8 months ago

Andrew15-5 commented 8 months ago

Here is the working example:

source

```typ #import "@preview/tablex:0.0.6": tablex, rowspanx, colspanx, cellx #set page(width: auto, height: auto) #set text(size: 10pt) #tablex( align: center + horizon, rows: 5mm, columns: (7mm, 10mm, 23mm, 15mm, 10mm, 70mm, 5mm, 5mm, 5mm, 5mm, 12mm, 18mm), ..range(5), cellx(rowspan: 3, colspan: 7)[], ..range(5), ..range(5), ..range(5), rowspanx(5)[], colspanx(3)[], colspanx(2)[], [], ..range(5), rowspanx(3)[], rowspanx(3)[], rowspanx(3)[], cellx(rowspan: 3, colspan: 2)[], rowspanx(3)[], colspanx(2)[], ..range(3), colspanx(2)[], ..range(3), colspanx(2)[], ..range(3), colspanx(4)[], colspanx(2)[], colspanx(2)[], ..range(3), rowspanx(3)[], cellx(rowspan: 3, colspan: 6)[], colspanx(2)[], ..range(3), colspanx(2)[], ..range(3), ) ```

part of output

![image](https://github.com/PgBiel/typst-tablex/assets/37143421/1f072025-bcd1-4f42-8a27-7e065fb6de48)

But adding x: 5, causes not only text on 1st, 5th, 9th, 11th rows to shift a bit, but also extends the last row's height:

source

```typ #import "@preview/tablex:0.0.6": tablex, rowspanx, colspanx, cellx #set page(width: auto, height: auto) #set text(size: 10pt) #tablex( align: center + horizon, rows: 5mm, columns: (7mm, 10mm, 23mm, 15mm, 10mm, 70mm, 5mm, 5mm, 5mm, 5mm, 12mm, 18mm), ..range(5), cellx(x: 5, rowspan: 3, colspan: 7)[], ..range(5), ..range(5), ..range(5), rowspanx(5)[], colspanx(3)[], colspanx(2)[], [], ..range(5), rowspanx(3)[], rowspanx(3)[], rowspanx(3)[], cellx(rowspan: 3, colspan: 2)[], rowspanx(3)[], colspanx(2)[], ..range(3), colspanx(2)[], ..range(3), colspanx(2)[], ..range(3), colspanx(4)[], colspanx(2)[], colspanx(2)[], ..range(3), rowspanx(3)[], cellx(rowspan: 3, colspan: 6)[], colspanx(2)[], ..range(3), colspanx(2)[], ..range(3), ) ```

part of output

![image](https://github.com/PgBiel/typst-tablex/assets/37143421/41fa6816-b8fe-46cd-8352-05037764997d)

If I remove the unnecessary ..range(5), then most rows' text will move and the second to last row now also will extend its height.

source

```typ #import "@preview/tablex:0.0.6": tablex, rowspanx, colspanx, cellx #set page(width: auto, height: auto) #set text(size: 10pt) #tablex( align: center + horizon, rows: 5mm, columns: (7mm, 10mm, 23mm, 15mm, 10mm, 70mm, 5mm, 5mm, 5mm, 5mm, 12mm, 18mm), cellx(x: 5, rowspan: 3, colspan: 7)[], ..range(5), ..range(5), ..range(5), rowspanx(5)[], colspanx(3)[], colspanx(2)[], [], ..range(5), rowspanx(3)[], rowspanx(3)[], rowspanx(3)[], cellx(rowspan: 3, colspan: 2)[], rowspanx(3)[], colspanx(2)[], ..range(3), colspanx(2)[], ..range(3), colspanx(2)[], ..range(3), colspanx(4)[], colspanx(2)[], colspanx(2)[], ..range(3), rowspanx(3)[], cellx(rowspan: 3, colspan: 6)[], colspanx(2)[], ..range(3), colspanx(2)[], ..range(3), ) ```

part of output

![image](https://github.com/PgBiel/typst-tablex/assets/37143421/a405c439-2eaf-4f8d-9fcd-fe10eb631280)

P.S. I'm using MuPDF in the screenshots.

PgBiel commented 8 months ago

MRE:

#import "@preview/tablex:0.0.7": tablex, cellx

#tablex(
  rows: 5pt,
  cellx(x: 0, y: 1)[a\ a\ a\ a]
)

Produces (Typst 0.10.0):

The last row is larger than it should be

The last row is internally auto-sized.

PgBiel commented 8 months ago

This was fixed for the next release, thanks for reporting! In the meantime, you can use tablex.typ from the 0.0.x branch - just download the file, place it in your project and import it.