Hi everyone! I’m writing an article about astronomy, and I’d like a page-wide schematic picture of the solar system on my title page. This is my code so far:
The problem is that the canvas automatically fits the image to the top and left edges of the page, and so the Sun ends up equidistant from these edges, despite supposedly having coordinates (3,-7). Is it possible to draw shapes where I actually want them to appear on the page, and just crop them if they go out of bounds? Ideally, I would like something like this (this was drawn in Asymptote):
As mentioned in the CeTZ manual, clipping is currently not supported. This means you can’t define a drawing box that restricts where lines are drawn—everything will be rendered regardless of the canvas boundaries.
A workaround is to place your canvas in the center of the page and shift it slightly, so the page edges effectively act as a “clip” for your solar system. You can even set the canvas as the page background:
Yeah, since CeTZ is a package for drawing, it will show a full drawing, so to use negative value to move the drawing into the opposite direction you would have to use move(), although depending on what you need, a place(dx: ..., dy: ..., cetz.canvas()) can be a better solution since it will by default start in the top left corner bypassing page margins if used as background or foreground.
Hi @thornoar, thanks for your question! If you feel the response you got has sufficiently answered your question, be sure to give it a checkmark . This will help others find the solution in the future. Thanks!
As an aside - even though CeTZ doesn’t support clipping, block does, so you can use the shifting trick even when you don’t want to fill the full page. In addition to move (which will affect where the canvas is but not its size), you could also use pad with negative values, so that Typst’s layouting (i.e. the surrounding clipping block) treats the canvas as smaller than it actually is.