#Text wrapping in tablex

24 messages · Page 1 of 1 (latest)

hoary pawn
#

I want the text to automatically line-wrap to not expand beyond the availible space, in the following example:
?render

#import "@preview/tablex:0.0.6": tablex, rowspanx, colspanx

#tablex(
  columns: (1fr,)*16,
  align: center + horizon,
  auto-vlines: true,
  header-rows: 1,

  /* --- header --- */
  colspanx(16)[*Bit Fields*],
  31,
  30,
  29,
  28,
  27,
  26,
  25,
  24,
  23,
  22,
  21,
  20,
  19,
  18,
  17,
  16,

  colspanx(6)[],
  [selcal_en],
  [test_mode_en],
  [vor_ident_code_en],
  [vor_ident_en],
  [vor_en],
  [loc_ident_en],
  [indent_morse_code_en],
  [mkr_beac_en],
  [gs_en],
  [loc_en],
)

Is there any way to achieve this?

#

?render

#import "@preview/tablex:0.0.6": tablex, rowspanx, colspanx

#tablex(
  columns: (1fr,)*16,
  align: center + horizon,
  auto-vlines: true,
  header-rows: 1,

  /* --- header --- */
  colspanx(16)[*Bit Fields*],
  31,
  30,
  29,
  28,
  27,
  26,
  25,
  24,
  23,
  22,
  21,
  20,
  19,
  18,
  17,
  16,

  colspanx(6)[],
  [selcal_en],
  [test_mode_en],
  [vor_ident_code_en],
  [vor_ident_en],
  [vor_en],
  [loc_ident_en],
  [indent_morse_code_en],
  [mkr_beac_en],
  [gs_en],
  [loc_en],
)
ashen flower
#

@hoary pawn Typst can’t break on underlines

#

As a workaround , add #sym.zws between each character to add break points

#

I don’t remember the exact code for that, it’s somewhere in #quick-questions

#

But basically you’d use a show rule with regex

hoary pawn
#

oh, that makes sense. Thanks for the fast reply! I will take a look

ashen flower
#

Something like

#{
show regex("\w"): it => it + sym.zws

tablex(…)
}

#

But note that a disadvantage of that is that the ZWS character goes to the final pdf

#

So users who copy your table’s contents will also copy zero width spaces

hoary pawn
#

Hmm, that is a disadvantage. Is it possible to temporarily change how typst finds possible break points?

ashen flower
#

I’m honestly not sure

#

I’ve heard of the -? Syntax

#

You could try that

#

I.e.

#

Using [#it;-?] in the show rule

#

Also note that the show rule uses \w in the regex which will only match a-z A-Z 0-9 _

hoary pawn
ashen flower
#

You could try . Instead to match any non-new line character (but that will cause infinite recursion with the zws approach)

ashen flower
#

There’s the hellscape workaround of using a show rule on dashes replacing them with []

#

Lol

#

But there’s probably a better way I’m not thinking of