Make bottom/top stroke invisible on block break?

Is there a way to have a the stroke of a breakable block change based on the breaking point? A bit like so:


For reference, I manually split the block and set the strokes here to show an example of what I meant.

1 Like

There is no standard inbuilt way to configure strokes on block breaks, but you can work around it by only applying the stroke on the left and right side of the block, and placing the top and bottom strokes as separate elements. This of course has limitations, especially when using rounded corners, but it should work in simple cases:

#let broken-block(..args) = layout(bounds => {
  let stroke = stroke(args.at("stroke", default: 0pt))
  let width = measure(..bounds, block(..args)).width

  // I'm using a block here instead of a line so that a
  // possible `show line: set block(spacing: ..)` rule
  // doesn't interfere with the spacing set to this block.
  let line = block.with(
    outset: (x: stroke.thickness / 2),
    width: width,
    stroke: stroke,
  )

  line(below: stroke.thickness / 2)
  block(..args, stroke: (x: stroke))
  line(above: stroke.thickness / 2)
})

// Use it just like a regular block.
#broken-block(
  fill: blue.lighten(80%),
  stroke: 1pt,
  inset: 1em,
  lorem(35)
)

image


Also, please try to keep questions in the Questions category, so they are easier to find for other users!

2 Likes

Thanks for the tip!

And sorry about that, I’ll make sure to properly tag my post next time.

There are some hacks listed in

1 Like

Hi @Regodin, don’t forget to tick :ballot_box_with_check: one of the responses if you got a satisfying answer. The answer you choose should usually be the response that you found most correct/helpful/comprehensive for the question you asked. Thanks!

1 Like