How do I get the title of the document in the centre of the header with the page number on the right?

I am trying to set up a template using the Chic-hdr package, so that the document title from a #set document(title:[]) will be entered in the centre field of the header with the page number on the right. I have the following code:

#set document(title: [ New Document ])

#import "@preview/chic-hdr:0.5.0": *

#set page(paper: "a7")

#show: chic.with(
  chic-footer(
    left-side: "",
    right-side: "" 
  ),

  chic-header(
    left-side: "",
    center-side: smallcaps( "x" ),
    right-side: chic-page-number(),
)
)
#set par(first-line-indent: 1em, spacing: 0.5em, justify: false)

#lorem(100)

I have not been able to find a coding to put the document title in Chic-hdr field to replace the “x”. Could someone help please?

I have also tried to modify @Andrew’s code in:

as follows:

#let title = [Document title]
#set page(
  paper: "a6",
  header: context {
 //   set text(8pt)
    let n = counter(page).display()
      align(center)[#title]; 
      align(right)[#n]
  },
)
#set par(justify: true)

#range(5).map(_ => lorem(50)).intersperse(parbreak()).join()

but, while it places “Document title” in the centre, it is raised above the expected position on the page, as if on a separate line from the page number.

Thanks.
:slight_smile:
Mark

Hi Mark,

you need context to be able to get the value from the document.

center-side: context smallcaps(document.title),

The second example has the problem, that align is a block level element, you can use a grid with 3 columns or use h(1fr) like this:

header: context {
  // set text(8pt)
  let n = counter(page).display()
  h(1fr)
  title //or document.title
  h(1fr)
  n
},