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
},
2 Likes

Thanks very much @flokl.

I’ve gone for the:

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

solution.

The problem with the documentation is that the examples bear little relation to what someone like me needs and just make it more complex. context is very much a case in point; your solution is simple, but there is no way I would have arrived at it having spent a long time going over the docs again and again, and trying to understand apparently relevant code from posts in this forum.

:slight_smile:
Mark

P.S. I have enclosed the code in backticks , but it’s not applying the colour coding and I don’t know why!

Different modes require different language tag specified in place of the info string: https://forum.typst.app/t/how-to-post-in-the-questions-category/11#p-29-body-3.

1 Like