# Page number in the margin and separator

I want to produce this kind of header.

My first attempt includes the use of fancyhdr package but still I can't figure out how it is possible to move the page number in the margin and put the | bold separator. Does anyone know if fancyhdr is capable of this kind of customization or should I look at titlesec – titleps packages?

\documentclass[a4paper, 12pt, twoside, openright, english]{book}
%
\usepackage{lipsum} % to produce dummy text
\usepackage[english]{babel}
%
\usepackage{fancyhdr}
\fancyfoot{}
\pagestyle{fancy}
\renewcommand{\sectionmark}[1]{\markright{\sffamily \itshape \thesection\ #1}}
\renewcommand{\chaptermark}[1]{\markboth{\sffamily \itshape\thechapter\ #1}{}}
\fancyhf{}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\begin{document}
%
\chapter{Basic principles for multi camera systems}
\lipsum[3-15] % dummy text
\section{Introduction}
\lipsum[3-15] % dummy text
\subsection{Image processing}
\lipsum[3] % dummy text
%
\end{document}

-
You only need to give the page number a zero width. E.g. \fancyhead[RO]{\makebox[0pt][l]{\raisebox{-3mm}[0pt][0pt]{\rule{1mm}{1cm}} \sffamily \bfseries \thepage}}. (The left side needs a mirror definition. – Ulrike Fischer Mar 8 '13 at 12:44
@UlrikeFischer oops your comment crossed with my answer, sorry – David Carlisle Mar 8 '13 at 12:46
@DavidCarlisle: It's the other way round: my comment crossed with your answer ;-). – Ulrike Fischer Mar 8 '13 at 12:53
That was really fast. Thank you both ;-) – dkc Mar 8 '13 at 12:56

\fancyhead[LE]{\leavevmode\smash{\llap{\sffamily \bfseries \thepage\ \rule[-1em]{5pt}{2em}}}}
\fancyhead[RO]{\leavevmode\smash{\rlap{\rule[-1em]{5pt}{2em}\ \sffamily \bfseries \thepage}}}

-

After the helpful comments above and a bit code manipulation, the final result is exactly what I was looking for. After all, fancyhdr can offer this kind of customization and I would like to share it here in case someone else need the final code to work towards something better...

\documentclass[a4paper, 12pt, twoside, openright, english]{book}
%
\usepackage{lipsum} % to produce dummy text
\usepackage[english]{babel}
\usepackage{fancyhdr}
\fancyfoot{}
\pagestyle{fancy}
\renewcommand{\sectionmark}[1]{\markright{\sffamily \itshape \thesection\ #1}{}}
\renewcommand{\chaptermark}[1]{\markboth{\sffamily \itshape\thechapter\ #1}{}}
\fancyhf{}
\fancyhead[LE]{\leavevmode\smash{\llap{\sffamily \bfseries \thepage\ ~\rule[-.5em]{2pt}{2em}} \leftmark}}
\fancyhead[RO]{\leavevmode\smash{\rightmark ~ \rlap{~\rule[-.5em]{2pt}{2em}\ ~\sffamily\bfseries\thepage}}}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\begin{document}
%
\tableofcontents % you can comment this one...
\chapter{Dummy Chapter Title with Many Words}
\lipsum[3-15] % dummy text
\section{Dummy Section Title with Many Words}
\lipsum[3-15] % dummy text
\subsection{Dummy Subsection}
\lipsum[3-5] % dummy text
\section{A Short Dummy Section}
\lipsum[3-10] % dummy text
%
\end{document}

-