# Headers with vertical rule with Koma-Script

I am trying to obtain the following headers with scrbook: numbers half-way into the margin, a a rule that extends up to (touches) the upper edge of the page, running heads should be within text margins. (I also wanted to make chapter titles with chapter numbers extending beyond the margin and a vertical rule also extending up to the upper edge of the page, but I guess I'll leave it for another question.)

So far I have come up with the following solution:

\documentclass[a4paper,DIV=classic]{scrbook}
\usepackage{scrpage2}
\usepackage{lipsum}

}

}

\begin{document}
\chapter{Um Capítulo}
\lipsum[1-10]
\section{Uma Seção}
\lipsum[15-20]

\chapter{Outro Capítulo}
\lipsum[1-10]
\section{Outra seção}
\lipsum[15-20]

\end{document}


However, I couldn't find a way to increase the height of the rule (if it goes beyond a certain limit it is superposed to the text), and the running heads are not perfectly aligned with the text block margin.

As Harish Kumar suggested in a comment, you can use \smash which typesets its contents in a box but ignoring its height and depth. The height for the rule is calculated automatically (\headheight-\topmargin+\headsep); also notice the use of \llap and \rlap to make the rule and the numbers protrude into the margins, but keeping the marks aligned with the margins.

\documentclass[a4paper,DIV=classic]{scrbook}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[portuguese]{babel}
\usepackage{scrpage2}
\usepackage{lipsum}

\llap{\pagemark~~~\smash{%
\hspace{2em}}%

\rlap{\hspace{2em}\smash{%
~~~\pagemark}}

\begin{document}

\chapter{Um Capítulo}
\lipsum[1-10]
\section{Uma Seção}
\lipsum[15-20]

\chapter{Outro Capítulo}
\lipsum[1-10]
\section{Outra seção}
\lipsum[15-20]

\end{document}


Some zoomed images for the headers of odd and even-numbered pages:

and

• Worked fine, what exactly does \dimexpr do? – Joseph Aug 2 '13 at 23:56
• @Joseph \dimexpr is an e-TeX macro allowing calculations with lengths. – Gonzalo Medina Aug 2 '13 at 23:57