How to expand marginalia header into outer margin without affecting margin text alignment?

Hello!

I’m using the marginalia package to format inset margin notes in the outer margins. Doing so shortens the header, which presents two problems for me.

  1. I would like to extend the header into the note margin itself.
  2. I would like the header text to remain centred according to the page text, and so not move when the header is extended.

I’ve attached a couple of screenshots, one of what I have at the moment, and one with what I would ideally like to have. I’m doing this manually but it only works for odd pages. I would like to have it handled on both odd and even pages by marginalia itself. Also when I do it manually the header text moves.

I’ve read through the PDF manual on the GitHub but I’m still unsure of how to achieve this. Does anyone have any ideas how I could do this, or if it’s not possible with marginalia?

Many thanks,
Reiwa

Hi!

If I understand correctly you want the frame around the header to expand into the margins, but the header text to stay centered above the body text?

It is true that there is no facility in marginalia for this, but we can fake it by placing the lines in their own wideblocks:

#set page(
  header: {
    set block(spacing: 5pt)
    wideblock(side: "both", line(length: 100%, stroke: 1pt + black))
    align(center)[Center Text]
    wideblock(side: "both", line(length: 100%, stroke: 1pt + black))
  }
)

(adjust the spacing and side parameters to your tastes)


If you want to have a proper block around your header, e.g. to give it a fill, you can use the marginalia.get-left() and marginalia.get-right() functions to get the proper measurements:

#set page(
  header: context {
    let left = marginalia.get-left()
    let right = marginalia.get-right()
    wideblock(
      side: "both",
      block(
        stroke: (y: 1pt + black),
        inset: (
          y: 5pt,
          left: left.width + left.sep,
          right: right.width + right.sep,
        ),
        width: 100%,
        fill: aqua,
        align(center)[Center Text] 
      )
    )
  }
)


here, if you only want it to extend to one side, you need to change side and set one of inset.left or inset.right to 0 depending on whether it is an even or odd page:

#set page(
  header: context {
    let left = marginalia.get-left()
    let right = marginalia.get-right()
    let is-odd-page = calc.odd(here().page())
    wideblock(
      side: "outer",
      block(
        stroke: (y: 1pt + black),
        inset: (
          y: 5pt,
          left: if is-odd-page { 0pt } else { left.width + left.sep },
          right: if is-odd-page { right.width + right.sep } else { 0pt },
        ),
        width: 100%,
        fill: aqua,
        align(center)[Center Text]
      )
    )
  }
)

3 Likes

Extending the margin only to the outer side was indeed exactly the solution I was looking for! Thank you very much for your help and thank you for creating such a great package, I’d be lost without it.

1 Like