[Tex/LaTex] ConTeXt: Draw a line under the headertext

contextheader-footerrules

Sometimes, in order to seperate the headertext from the text area, I need draw a line just under the headertext.

\setuppagenumbering
[location=,
 alternative=doublesided]

\definepagebreak
[chapterpagebreak]
[yes,header,footer,right]

\setuphead
[chapter]
[style=\bfc,
 header={empty,nomarking}, 
 page=chapterpagebreak]

\def\pageoddoreven{%
\ifodd\pagenumber
  {\getmarking[sectionnumber]\hskip1em\getmarking[section][first]}
\else
  {Chapter~\getmarking[chapternumber]\hskip1em\getmarking[chapter]}
\fi}

\setupheadertexts
[text][\pageoddoreven][pagenumber]

\setupheader
[style=bold,after=\thinrule]

\starttext
\chapter{First Chapter}
this is the first chapter
\page   
the second page of the first chapter
\chapter{Second Chapter}
this is the second chapter
\page
the second page of the second chapter
\stoptext

but the \thinrule will be across the whole page, that is what I what.

thinrule

I want a line that is only across the text area, not extending to the left and right margin. How can I draw this line?

Best Answer

As Timothy Li noted, Aditya's solution draws the line on every page. It is possible to define a header (or footer) that only appears on pages with content. For my purposes, I used a footer, but the following code could equally be applied to just the header:

\setuphead[chapter][
  header=empty,
]

% Define the appearance for the section name in the footer.
\defineframed[FooterSection][
  frame=off,
  topframe=on,
  align=flushleft,
  width=\makeupwidth,
  rulethickness=1.6pt,
  location=bottom,
  foregroundstyle=\tfx\ss,
  height=broad,
  top={\blank[small]},
]

% Define the appearance of the page number in the footer.
\defineframed[FooterPage][
  frame=off,
  location=bottom,
  foregroundstyle=\tfx\bold\ss,
]

% Include the section name and page number in the footer.
\setupfootertexts
  [\FooterSection{\getmarking[section]}]
  [\FooterPage{\pagenumber}]

\starttext
  \startfrontmatter

  \startstandardmakeup
    \startalignment[middle]\tfa{Title Page}\stopalignment
  \stopstandardmakeup

  \setuppagenumbering[conversion=romannumerals]
  \setcounter[userpage][1]
  \completecontent
  \stopfrontmatter

  \startchapter [title=alpha] \stopchapter
    \startsection[title=alphasec] \stopsection
  \startchapter [title=beta]  \stopchapter
    \startsection[title=alphasec] \stopsection
  \startchapter [title=gamma] \stopchapter
    \startsection[title=alphasec] \stopsection
\stoptext