Henrik
Henrik

Reputation: 203

restrict length of outline entry

Some of my figures have long captions, which results in ugly outlines.

long outline entry

Is there a way to either truncate the outline.entry text, set a maximum width for the text length or trigger a linebreak after N characters, such that the outline.entry would compile to this:

enter image description here

I inspected the source and managed to modify the part after the section title with show outline.entry: set box(...) but I couldn't figure out how to access what comes before the BoxElem.

Upvotes: 0

Views: 147

Answers (1)

ntjess
ntjess

Reputation: 1470

You can indeed construct your own outline.entry show rule in typst instead of rust. The key ingredient is clip: true on the box surrounding it.body:

#show outline.entry: it => {
  style(styles => {
    let line-height = 1em
    // "columns" width determines how much of the caption should show
    grid(columns: (2fr, 1fr))[
      #box(it.body, height: line-height, clip: true)
    ][
      #box(width: 1fr, it.fill)
      #box(it.page)
    ]
  })
}
#outline(target: figure)

#figure(caption: [#lorem(150)])[
  A figure
]

enter image description here

Upvotes: 0

Related Questions