How do I align content in a grid with CeTZ?

I have been using CeTZ besides Fletcher for some time now, but there are just a few small hiccups with the integration of these two packages. I have reflected that the only real reason I have been using Fletcher is because it provides a very nice system of vertical alignment, with its ‘flexible grid’. Would it be possible to emulate a similar sort of system with purely CeTZ?

As below, the size of each column adjusts to fit the content.

I have attempted to use a grid to manually accomplish this sort of thing, however, the inflexibility is a serious hindrance in comparison to Fletcher.

Functionality that is not required:

  • Drawing edges between ‘nodes’/’cells’, I am fine with having each cell sit isolated from each other in this way
  • Debug utilities like Fletcher
  • Dynamically creating ‘rows’ of content (I am happy to have to pre-define this).
  • Some ‘beautiful’ syntax; I am happy with however verbose this happens to be

I was hoping there would be some simple CeTZ-native way to accomplish this, but after reading through the docs it does not seem like there is.

Thanks

For your example picture, you could use anchors to achieve this in CeTZ. Although I don’t think this scales well for arbitrary grids, since it requires all cells to be adjacent in some way.

#import "@preview/cetz:0.4.0"

#cetz.canvas({
  import cetz.draw: *
  set-style(content: (frame: "rect", stroke: black, fill: white, padding: .1))
  content((0, 0), [Some Large Middle Content], name: "root")
  content("root.north-west", [a], anchor: "south-east")
  content("root.north", [b], anchor: "south")
  content("root.north-east", [c], anchor: "south-west")
})

Also, is there a specific reason why you posted this in the General category? I think this post fits better in the Questions category with a title such as “How do I align content in a grid with CeTZ”?

Thanks Jane,

Yes sorry, this should in fact have been a question my mistake.

Just a follow-up, do you know whether it would be possible to implement some function or system that could automatically handle anchor positioning given some constraints? I have not seen such a use case online (of course, considering that in most cases people would opt for the Fletcher library).