5

The MWE below prints the same text (i.e., chapter title) in the middle section of ALL (recto and verso) page headers. Is it possible to print different texts (e.g., author name on verso pages and chapter title on recto pages) in the middle section of headers?

\mainlanguage[en]
\language[en] 

\setuplayout[grid=yes]
\setupindenting[yes,small]

% Text in the middle section of ALL headers (both recto and verso pages).
\setupheadertexts[chapter]
% Page number on the header. Recto pages: on the right; verso pages: on the left.
\setupheadertexts[][pagenumber][pagenumber][]
% Set up headers.
\setupheader[state=normal, style=sc]

% Place page number in the middle of the footer on chapter title pages.
\definetext[chapterpagenumber][footer][pagenumber]
% Chapter
\setuphead
    [chapter]
    [align=middle,header=empty,footer=chapterpagenumber,number=no,page=right,textstyle=WORD]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\starttext
    \chapter{First Chapter}
        \input knuth
        \input knuth
        \input knuth
        \input knuth
        \input knuth
        \input knuth
        \input knuth
        \input knuth
        \input knuth
        \input knuth
        \input knuth
        \input knuth
\stoptext
4

The ConTeXt header layout is not super flexible but you can achieve your desired layout with a little bit of extra work. There are three ingredients:

  1. You want to distinguish between recto and verso pages, so you probably want your margins to adapt to that automatically as well. To this end you tell ConTeXt explicitly that you want doublesided typesetting. Also we turn off the page number because we want to place that manually.

    \setuppagenumbering[alternative=doublesided,location=]
    
  2. Use document metadata. Instead of \starttext use \startdocument, which does exactly the same thing as \starttext but allows you to set document variables. If you enable hyperlinks (\setupinteraction[state=start]) this metadata will also be automatically filled into the PDF properties.

    \startdocument
      [metadata:author={A. U. Thor},
       metadata:title={A short story}]
    
  3. Now we setup the headers manually (to some extent). You already got the pagenumber thing, so we start from there. In the left header of the verso page we fill in {\hfill\getmarking[chapter]\hfill} and on the recto page we use {\hfill\documentvariable{metadata:author}\hfill}. The \hfill will override the left and right justification and center the header.

    \setupheadertexts
      [{\hfill\getmarking[chapter]\hfill}][pagenumber]
      [pagenumber][{\hfill\documentvariable{metadata:author}\hfill}]
    

Full example:

\mainlanguage[en]
\language[en] 

\setuplayout[grid=yes]
\setupindenting[yes,small]

% Set up headers.
\setuppagenumbering[alternative=doublesided,location=]
\setupheadertexts
  [{\hfill\getmarking[chapter]\hfill}][pagenumber]
  [pagenumber][{\hfill\documentvariable{metadata:author}\hfill}]
\setupheader[state=normal, style=sc]

% Place page number in the middle of the footer on chapter title pages.
\definetext[chapterpagenumber][footer][pagenumber]
% Chapter
\setuphead
    [chapter]
    [align=middle,header=empty,footer=chapterpagenumber,number=no,page=right,textstyle=WORD]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\startdocument
  [metadata:author={A. U. Thor},
   metadata:title={A short story}]

    \chapter{First Chapter}
        \input knuth
        \input knuth
        \input knuth
        \input knuth
        \input knuth
        \input knuth
        \input knuth
        \input knuth
        \input knuth
        \input knuth
        \input knuth
        \input knuth

\stopdocument
| improve this answer | |
  • Thank you very much, your solution works perfectly. – Kutt Dec 13 '19 at 22:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.