I have the following code:

\documentclass{article}

\makeatletter
}
\makeatother
\begin{document}

\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:

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.

• Would you consider using titleps(a sibling of titlesec)? – Bernard Mar 27 '15 at 13:46
• @Bernard no... The problem is, that I have a medium complex document class with already predefined headers and footers. I don't want to add another layer of complexity on top of it, so I wanted to have a solution based on the LaTeX's commands for headers. – topskip Mar 27 '15 at 14:06

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
}
\makeatother

• yes this is a nice alternative in the in the non-color case. In color it fails for same reason mine did (there is an extra \hbox{{ ...}} around the heading to constrain colour specials) Although given this information you should be able to fix:-) (see my not so pretty edited answer) – David Carlisle Mar 27 '15 at 17:39
• Yes, the usage is simple in plain TeX: \headline={\myhrule foo\hfil bar}, but LaTeX brings complications (as usual:). When color LaTeX package is loaded then \aftergroup\myhrule works. Note: only one \aftergroup. – wipet Mar 27 '15 at 18:02
• That's cool. I don't understand it yet, but less \aftergroups than David's solutions – topskip Mar 27 '15 at 20:16
• @wipet David told me that your answer is better than his answer, but he also told me that I should not tell you. So ignore my comment from now and accept the fact that some uniDentified Person Came here and suggested me to use your answer. – topskip Mar 27 '15 at 20:21
• @topskip: I see what you did there. :) I think we could agree that DPC = Donald P. Cnuth. :) – Paulo Cereda Mar 28 '15 at 11:05

You can simply add a rule after the box that holds the heading:

\documentclass{article}

\makeatletter
\def\myhrule{\vskip1ex\hrule height 5pt}
}
\makeatother
\begin{document}

\section{Introduction}
foo bar baz

\end{document}


Or if you have color loaded

\documentclass{article}

\usepackage{color}

\makeatletter
\def\myhrule{\vskip1ex\hrule height 5pt}
\aftergroup\aftergroup\aftergroup\aftergroup\myhrule}
\aftergroup\aftergroup\aftergroup\aftergroup\myhrule}
}
\makeatother
\begin{document}

\section{Introduction}
foo bar baz

\end{document}

• Looks much better, but it doesn't work with my real document.... ! Missing \endgroup inserted. <inserted text> \endgroup . I am not too keen on reducing the problem right now. – topskip Mar 27 '15 at 14:28
• @topskip fixed (My earlier self added extra groups to latex's heading code to control colour specials so my current self added a few extra \aftergroup to escape) – David Carlisle Mar 27 '15 at 15:22
• @topskip see tex.stackexchange.com/a/232003/1090 – David Carlisle Mar 27 '15 at 20:05
• OK, trivial then. I understand ;) (No, I think I understand why the many \aftergroup, but I would not have found out about the extra group the color package adds). – topskip Mar 27 '15 at 20:09

You can just under line them.

\documentclass{article}
\usepackage[normalem]{ulem}

\makeatletter
}
\makeatother
\begin{document}

\section{Introduction}
foo bar baz
\clearpage
\section{Introduction}
foo bar baz

\end{document}


You can change the thickness and depth of the rule by

\setlength{\ULdepth}{2ex}
\renewcommand{\ULthickness}{2pt}


Same with soul:

\usepackage{soul}

\makeatletter
}
\makeatother


The depth and thickness can be changed by

\setul{2ex}{2pt}


• @topskip I have added \setul{2ex}{2pt} for soul too. :) – user11232 Mar 27 '15 at 13:33
• Bad boxes are here because between foo and bar isn't infinitely stretchable glue, only normal space is here. You need to declare \def\@evenhead{\uline{foo\hfil bar}} but soul package doesn't work with this. – wipet Mar 27 '15 at 13:35