6

In Showcase of beautiful typography done in TeX & friends Marc van Dongen shows his book LaTeX and Friends, https://tex.stackexchange.com/a/46348/15360.

He uses a specific page header as can be seen in the pictures he shows us.

Page number <vertical rule> Chapter number

or

Chapter name <vertical rule> Page number

I really like it and would like to get the same format or very similar to it if possible and was wondering how this can be achieved?

enter image description here

WG-
  • 2,860

2 Answers2

8

One option using fancyhdr and the offsets provided by the package. Using

\fancyhfoffset[OR,EL]{\dimexpr\marginparsep+\marginparwidth\relax}

the headers are offset by an amount equal to \marginparsep+\marginparwidth to the right on odd-numbered pages and to the left on even-numbered ones. Then the actual headers are placed using

\fancyhead[OR]{\textsc{\leftmark}\quad\smash{\rule[-.2ex]{1pt}{4cm}}\quad\thepage}
\fancyhead[EL]{\thepage\quad\smash{\rule[-.2ex]{1pt}{4cm}}\quad\textsc{\chaptername~\thechapter}}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}

A complete example code:

\documentclass{book}
\usepackage{fancyhdr}
\usepackage{lipsum}

\pagestyle{fancy}
\fancyhf{}
\fancyhfoffset[OR,EL]{\dimexpr\marginparsep+\marginparwidth\relax}
\fancyhead[OR]{\textsc{\leftmark}\quad\smash{\rule[-.2ex]{1pt}{4cm}}\quad\thepage}
\fancyhead[EL]{\thepage\quad\smash{\rule[-.2ex]{1pt}{4cm}}\quad\textsc{\chaptername~\thechapter}}
\renewcommand\headrulewidth{0pt}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}

\begin{document}

\chapter{Test chapter}
\lipsum[1-40]

\end{document}

enter image description here

Gonzalo Medina
  • 505,128
  • Instead of \enspace\enspace you could use \quad. By the way, I don't know where I read it (and how “important” it is) but \enskip is the LaTeX preferred way, instead of \enspace. – Manuel May 26 '14 at 01:48
  • @Manuel I changed to \quad. In this case, there's no difference between \enspace and \enskip; both are kernel commands: the former is a \kern: \def\enspace{\kern.5em } the other is a \hskip: \def\enskip{\hskip.5em\relax}. – Gonzalo Medina May 26 '14 at 01:57
  • Using \enspace may be dangerous if it happens to fall at where a paragraph should start, because it would issue a vertical space; \enskip would start horizontal mode, instead, but allowing a line break. A header is normally typeset in restricted horizontal mode, so there's no difference between the two, in that case. – egreg May 26 '14 at 09:27
3

I've tried to rebuild this with pure komascript and came to this solution:

\documentclass[DIV=10,twoside]{scrreprt}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[automark]{scrlayer-scrpage}
\usepackage{ragged2e}
\usepackage{calc}
\usepackage{layout}
\usepackage{xcolor}
\usepackage{blindtext}
\usepackage{XCharter}
\usepackage{cabin}
\pagestyle{headings}
\setkomafont{pageheadfoot}{\normalfont\sffamily\scshape}
\setkomafont{pagenumber}{\normalfont\sffamily}

%setting lengths
\newlength{\ruleWidth}
\setlength{\ruleWidth}{2pt}
\newlength{\pageNumperSpace}
\setlength{\pageNumperSpace}{35pt}
\newlength{\pageNumberHeaderSkip}
\setlength{\pageNumberHeaderSkip}{-\paperwidth+\textwidth+\hoffset+1in+\oddsidemargin}
\newlength{\chapterHeaderSkip}
\setlength{\chapterHeaderSkip}{\pageNumberHeaderSkip+1em+\pageNumperSpace+\ruleWidth}

% scrlayer definitions
\rohead{\smash{\textcolor{black}{\rule[-4pt]{\ruleWidth}{\voffset+\topmargin+\headheight+1in}}}\makebox[\pageNumperSpace][c]{\oldstylenums\pagemark}\hspace{\pageNumberHeaderSkip}}
\lehead{\hspace{\pageNumberHeaderSkip}\makebox[\pageNumperSpace][c]{\oldstylenums\pagemark}\smash{\textcolor{black}{\rule[-4pt]{\ruleWidth}{\voffset+\topmargin+\headheight+1in}}}}
\cohead{\raggedleft{\headmark} \hspace{\chapterHeaderSkip}}
\cehead{\hspace{\chapterHeaderSkip} \raggedright{\headmark} }

\begin{document}
\Blinddocument
\end{document}

enter image description here

Stefan Braun
  • 1,244