How can I add extra spacing above 'heading 1' on new pages

Thanks to help from many here, most of my issues setting up my template have been resolved, but I have one more. Here is my code example, modified to take in recent solutions.

// Page layout including headers and footer, removed on blank pages
#import "@preview/hydra:0.6.1": hydra

/// Check whether a page is an empty page.
#let is-page-empty() = {
  let page-num = here().page()
  query(selector.or(<ep-start>, <ep-end>))
    .chunks(2)
    .any(((start, end)) => {
      start.location().page() < page-num and page-num < end.location().page()
    })
}

#set page(
  paper: "a7",
  margin: (inside: 1.5cm, outside: 1cm, y: 1.5cm),
  header: context if not is-page-empty() {
    if calc.odd(here().page()) {
      align(right, smallcaps(hydra(1)))
    } else {
      align(left, emph(hydra(2)))
    }
    v(-0.5em
  )
    line(length: 100%)
  },
  footer: context if not is-page-empty() {
    align(center, counter(page).display())
  },
)

#show pagebreak: it => [#metadata[]<ep-start>] + it + [#metadata[]<ep-end>]

#show heading.where(level: 1): it => {
  set align(center)
  set text(18pt, weight: "semibold")
  pagebreak(weak: true, to: "odd") + it
}
#show heading.where(level: 2): set text(14pt, weight: "semibold")

= Part 1

#lorem(75)

== Section 1.a

#lorem(50)

= Part 2

#lorem(75)

== Section 2.a

#lorem(25)

However, I would like, book style, to have a separation, of say 5em, between the header and the Part heading. I have tried everything I can think of using a block or #v but, with my efforts, at best they have had no effect, at worst the heading disappears completely.

Can someone please help me to accomplish this? Thanks.

:slight_smile:
Mark

Using something like this with v should work just fine:

#show heading.where(level: 1): it => {
  set align(center)
  set text(18pt, weight: "semibold")
  pagebreak(weak: true, to: "odd")
  v(5cm)
  it
}

(Whether to write it like that or with + doesn’t matter, it’s the same thing)

pagebreak(weak: true, to: "odd") + v(5cm) + it

Thanks for the reply, but that adds the space after the heading, not above the heading, which is where I want it.

:slight_smile:
Mark

Hm. In my example it didn’t do that, so maybe you can share the complete code?

Ok I can take your example and it seems to work. There’s a separate thing with hydra (just tweak what happens on new part pages) that can be solved separately.

// Page layout including headers and footer, removed on blank pages
#import "@preview/hydra:0.6.1": hydra

/// Check whether a page is an empty page.
#let is-page-empty() = {
  let page-num = here().page()
  query(selector.or(<ep-start>, <ep-end>))
    .chunks(2)
    .any(((start, end)) => {
      start.location().page() < page-num and page-num < end.location().page()
    })
}

#set page(
  paper: "a7",
  margin: (inside: 1.5cm, outside: 1cm, y: 1.5cm),
  header: context if not is-page-empty() {
    if calc.odd(here().page()) {
      align(right, smallcaps(hydra(1)))
    } else {
      align(left, emph(hydra(2)))
    }
    v(-0.5em
  )
    line(length: 100%)
  },
  footer: context if not is-page-empty() {
    align(center, counter(page).display())
  },
)

#show pagebreak: it => [#metadata[]<ep-start>] + it + [#metadata[]<ep-end>]

#show heading.where(level: 1): it => {
  set align(center)
  set text(18pt, weight: "semibold")
  pagebreak(weak: true, to: "odd") + v(5em) + it
}
#show heading.where(level: 2): set text(14pt, weight: "semibold")

= Part 1

#lorem(75)

== Section 1.a

#lorem(50)

= Part 2

#lorem(75)

== Section 2.a

#lorem(25)

Thank you for this. In all my attempts the one thing I did not try was putting + before the (5em)! You say:

Ok I can take your example and it seems to work. There’s a separate thing with hydra (just tweak what happens on new part pages) that can be solved separately.

Absolutely, but as always I’m stymied in trying to combine the “tweak” with existing code. The manual says:

If hydra is used with ⟨skip-starting⟩: true on such a starting page, it will not show anything. This is turned on by default.

As with the code lines:

 footer: context if not is-page-empty() {
    align(center, counter(page).display())}

where the default placing of the page number is overridden, so too adding the +(5em) seems to override the default and we end up with

So, it seems that the “tweak” in question is to include starting-page: true somewhere in the code, or, in this case to turn on “Book mode”:

If hydra is used on a leading page with ⟨book⟩: true, then it will not show an active element, if it is still visible on the trailing page. This is turned off by default.

But where this should be placed in the code and in what form is not made at all clear to the likes of me! Again I just end up with errors that I can’t resolve.

:slight_smile:
Mark

Page 5 of the hydra manual contains the fix for your exact problem :).

// do
#show heading: it => block(v(8cm) + it
// don't
#show heading: it => v(8cm) + it

You have to wrap the vertical spacing and the heading in a block.

...
pagebreak(weak: true, to: "odd")
block(v(5em) + it)
...
2 Likes

Thank you so much!

I have to say that I had read the manual many times, but couldn’t get that to work; it just returned an error that I couldn’t resolve, so I don’t know what I had typed wrong. As I have said, where the example code doesn’t match the more complex code you already have working, marrying the two is not immediately obvious to us beginners.

:slight_smile:
Mark

1 Like