This post discusses headings in particular, but the behavior is identical with regular text, and likely any piece of content.
The size of the header is fixed, so inserting a v() in it just moves the content in it around. I suppose it is possible to move the entire body accordingly, or change height of the header together with the spacing of… something… yikes.
header, the page’s header; not heading. I hate how similar is the terminology.
I want to modify the spacing in between the header and the heading or any other piece of content, not from headings to anything else.
In fact, I got them confused while writing this paragraph…
Hello, the red-coloured spacing in your image can be increased by using header-ascent values greater than the default, which at the moment is 30% + 0pt. Lower values are of course also valid, but then you will probably soon need to increase the top margin in order to avoid overlapping contents.
It’s an argument for page that behaves like footer-descent.
Thank you. Somehow, I missed the existence of this parameter. Although, this doesn’t make “moving the text down” that simple. I suppose I can modify the height of the top margin and the header ascent equally.
let top-margin = 2.5/21 * 8.5in // us-letter
let header-to-body = 0.3 * top-margin // default header ascent
let delta = 2em - header-to-body // 2em being par.leading
set page(margin: (top: top-margin + delta), header-ascent: header-to-body + delta)
Works. A note: even though I set the page.paper as "us-letter", and par.leading as 2em, accessing them later in the same context block returns the old values. This seems to be the way typst handles context in general:
Although unwanted in this case, I suppose there’s a good reason for this behavior. Regardless, a “margin buffer/pad” parameter would have been useful. Again, I suppose there is a good reason for it not being implemented. I also doubt my solution is the cleanest one, but it does work.
#import "@preview/scaffolder:0.2.1": get-page-margins
#set page("us-letter", header: "text")
#set par(leading: 2em)
#show: it => context {
let delta = par.leading - page.header-ascent.ratio * get-page-margins().top
set page(
margin: (top: get-page-margins().top + delta),
header-ascent: page.header-ascent + delta,
)
it
}
context is a “cut off” line, you change the styling after the context was already cut off, hence no changes. The documentation explains it. Context – Typst Documentation