PgBiel/typst-tablex

Rotating cell contents seems to calculate dimensions wrong

ja-he opened this issue · 7 comments

What I originally wanted to do (not being a huge typst expert) was something like rowspanx(7)rotate(-90deg)[*Components*] but that does not compile; fair enough.

My quick solution so far was to use cellx directly: cellx(rotate(-90deg)[*Component*], rowspan:7).
That does compile, and work mostly as expected except for the fact that it hyphenates the word when there is not enough left-right space for it, even though it has been rotated to be written bottom-to-top, where there is plenty of space.

Heres a small yet more complete example that showcases my issue:

slightly broken example / example to showcase broken cell-content rotation
  #tablex(
    columns: (2em, auto, auto),
    inset: 10pt,
    align: center + horizon,
    auto-vlines: true,
    header-rows: 1,
    [],
    [*NTIA*]                       , [*BSI*],
    cellx(rotate(-90deg)[*SBOM*], rowspan:2),
    [Author of SBOM Data]          , [_Creator of SBOM_],
    [Timestamp]                    , [_Timestamp_],
    cellx(rotate(-90deg)[*Component*], rowspan:7),
    [Supplier Name]                , [_Creator of the Component_],
    [Component Name]               , [_Component Name_],
    [Version of the Component]     , [_Version of the Component_],
    [Other Unique Identifiers]     , [],
    [Dependenciy Relationships]    , [_Dependencies from other Components_],
    []                             , [_License_],
    []                             , [_Hash-value of Executable Component_],
  )

that turns into this, where you can clearly see the word broken up when it has enough space.
2023-09-02_142703

I would guess that "SBOM" simply cannot be hyphenated by however typst does hyphenation.

  • the issue seems pretty clear (width seems to be calculated regardless of rotation)
  • I don't know if this is an issue with this package
  • I don't know if my use of the package is still within the intended uses
  • (but) I would say this is a fairly common thing to do in tables to maximize space efficiency

(As an aside, I discovered this package 20 minutes before my issue and it works wonderfully and is explained well, so thank you for the good work on it)


Further details:

  • It seems 0.0.5 fixes something with rotation, but my import line looks like this: #import "@preview/tablex:0.0.5": tablex, rowspanx, colspanx, cellx so I think this is not fixed in 0.0.5
  • I am on typst 0.7: typst 0.7.0 (da8367e1)

In case anybody comes across this and also is wondering how to force typst to not hyphenate, you can just set hyphenate:false on #text so in my case I would write the following:

cellx(text(hyphenate:false,rotate(-90deg)[*Component*]), rowspan:7)

I'm not sure that is easy to solve by means of this library. rotate only rotates visually, but it has the same effect on layout as if without rotation. You could try wrapping your text in a box or something like that.

What I originally wanted to do (not being a huge typst expert) was something like rowspanx(7)rotate(-90deg)[Components] but that does not compile; fair enough.

Yeah, the juxtaposition shorthand only works for [ ] directly. You're looking for rowspanx(7, rotate(-90deg)[...])

`rowspan(7, rotate(-90deg)[...])

that makes perfect sense, thank you.

You could try wrapping your text in a box or something like that.

I tried box any of the tree places I could think of, to no avail, so I don't think that works.

edit: It does work! just had to replace the outer text I had instead of going over it:
rowspanx(7, box(rotate(-90deg, [*Component*]))) 🎉

But in any case, ...

rotate only rotates visually, but it has the same effect on layout as if without rotation.

...then I would say this is not an issue with the package, so feel free to close it. 🙂

Cheers!

I think you're right that there could be some better info on the docs at least, this indeed seems like a problem that one could stumble upon a bit more often.

btw, you could also try this (I've added it to the README as well): typst/typst#528 (comment)