[Tex/LaTex] Underline a page head

header-footerrules

I have the following code:

\documentclass{article}

\makeatletter
\renewcommand\ps@headings{
  \def\@evenhead{foo bar}
  \def\@oddhead{foo bar}
}
\makeatother
\begin{document}
\pagestyle{headings}

\section{Introduction}
foo bar baz

\end{document}

(This is just an example. The real document is a bit more complicated…)

How can I have a rule below the »foo bar« header?

I'd like to get something like this:

header with horizontal rule

That is: a rule size \hsize. I don't want to use fancyhdr.

Edit: More requirements: I need to configure the rule thickness and the distance between the words »foo … bar« and the horizontal rule.

Best Answer

My \myhrule for rules in headers looks slight different than David's. The position of the heading text doesn't depend on the depth of the text. And, of course, I needn't any additional package.

\makeatletter
\def\myhrule{\lower1ex\null\vadjust{\hrule}}
\renewcommand\ps@headings{%
  \def\@evenhead{foo\hfill bar\myhrule}%
  \def\@oddhead{foo\hfill bar\myhrule}%
}
\makeatother