Minimum row height

I need to specify the minimum height of a row in a grid (or a table), but i can’t find any mention in the docs. By minimum height i mean that a row should be at least, say, 50pt high, but grow according to the content if the content is more than 50pt high. I’m surprised of seeing no mention in the docs, because i think this is quite a basic feature. Am I missing something?

1 Like

Technically, you can increase cell inset. I think it probably is a missing feature, but no one so far created an issue.

You can use cell metadata pinning trick in How to distribute column widths equally for specific rows in a table? - #4 by Andrew, How to avoid that a large table footer widens the whole table? - #7 by sijo, How can I robustly make (unknown) tables span the full page width? - #11 by bluss. Then you can check the height difference between opposite cell sides and conditionally include a block with min-height height.

I don’t think that feature exists for grids and tables. The question then becomes, can Typst do this at all and is it reachable in a good way for the user. This is one way to do it:

#set block(stroke: 0.2pt + blue)
#let minheight(h, body) = layout(
  available => {
    let size = measure(body, ..available)
    let args = if size.height < h { (height: h) }
    block(..args, body)
  }
)
#table(
  columns: 2,
  minheight(40pt)[A], [B],
  [C], [D]
)

since the block in question is inside a cell, I had to subtract the insets (default 5pt) from the desired row height (50pt) in this case.

I have been using invisible grids for this purpose:

#let magic-cell(min-height-without-inset, body) = grid(
  columns: (0pt, auto),
  v(min-height-without-inset), body,
)

#table(
  columns: 2,
  magic-cell(40pt)[A], [B],
  [C], [D],
  magic-cell(40pt)[A \ A \ A \ A \ A], [B],
)

Hard to tell if this solution is less hacky than bluss’…

3 Likes

No context/layout means that your solution is better any day of the week, better to use constructions that are using the natural sizing of elements like that.

1 Like

thank you for your answers. i’ll look into your solutions – both seem elegant and easy to understand – and see what works better for my use case.
(still baffled that typst doesn’t have min-height built-in though)

1 Like