5

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}
\addtokomafont{pagenumber}{\sffamily \bfseries}
\addtokomafont{pagehead}{\sffamily}
\addtokomafont{chapter}{\sffamily \bfseries}

\pagestyle{scrheadings}
\clearscrheadfoot

\setheadwidth[-0.5\marginparwidth]{textwithmarginpar}

\lehead{
\hspace{1em}\pagemark~~~\rule[-0.4ex]{0.4pt}{5mm}\hspace{2em}\headmark
}

\rohead{
\headmark\hspace{2em}\rule[-0.4ex]{0.4pt}{5mm}~~~\pagemark\hspace{1em}
}

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

0

1 Answer 1

7

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}

\addtokomafont{pagenumber}{\sffamily \bfseries}
\addtokomafont{pagehead}{\sffamily}
\addtokomafont{chapter}{\sffamily \bfseries}

\pagestyle{scrheadings}
\clearscrheadfoot

\lehead{%
\llap{\pagemark~~~\smash{%
  \rule[-0.4ex]{0.4pt}{\dimexpr\headheight-\topmargin+\headsep\relax}}%
  \hspace{2em}}%
\headmark}

\rohead{%
\headmark%
\rlap{\hspace{2em}\smash{%
  \rule[-0.4ex]{0.4pt}{\dimexpr\headheight-\topmargin+\headsep\relax}}%
  ~~~\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:

enter image description here

and

enter image description here

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

You must log in to answer this question.