# How to write chapter or section headers beside the page margin ?

I am using winedt on windows.
My question is how to make a book page style like the following pic with variations of displaying either chapter or section headers, according to page number, beside a vertical margin.

Thanks for help in advance.

@Herbert: The following pic is what I get after copy>paste in a new file

I really appreciate your help, however, what I need is a page style analogous to my first attached pic in my question.

-
Good question! But the answer will have very little to do with your operating system or text editor (which is why I removed those tags). What document class are you using? – Matthew Leingang Mar 15 '11 at 15:16
I am using "scrbook" class from "KOMA–Script". – Diaa Abidou Mar 15 '11 at 16:12

That can be done with package fancyhdr which allows to write page numbers and running headers elsewhere.

\documentclass[a4paper,10pt,twoside]{book}
\usepackage[english]{babel}
\usepackage{xcolor,blindtext}

\usepackage{geometry}
\geometry{paperheight=239mm,paperwidth=169mm,tmargin=5mm,textwidth=124mm,textheight=195mm,
marginparsep=2mm,marginparwidth=18mm}
\usepackage[color=red,cam,a4,center]{crop}

\usepackage{fancyhdr}
\colorlet{TitleBlue}{blue}
\fancyhf{}

\setlength\fboxsep{0pt}%
\colorbox{black!80}{%
\makebox[22mm]{\hfill
\ifnum\value{chapter}>0
\textcolor{white}{\fontsize{18}{19}\selectfont\thechapter}\
\fi
\rule[-2.85pt]{2mm}{12mm}%
}%
}}%
\color{TitleBlue}%<========================================
\fontsize{9}{9}\selectfont\leftmark}%\MakeUppercase{\leftmark}}
\rightmark
\makebox[22mm]{}}
\fancyfoot[LE]{\leavevmode%
\llap{\thepage\ \rule[-13mm]{.6pt}{18mm}\hspace{1mm}}
\hfill{\normalfont\today}% %<------ svn
}
\fancyfoot[RO]{\leavevmode
{\normalfont\today}%<------ svn
~\hfill \rlap{\hspace{1mm}\rule[-13mm]{.6pt}{18mm}\ \thepage}%
}

\pagestyle{fancy}

\begin{document}
\tableofcontents
\chapter{foo}\blindtext[3]\par\blindtext[3]
\chapter{bar}\blindtext[7]
\chapter{baz}\blindtext[8]

\end{document}

-
I am sorry, but would you show me an example of Latex syntax ?. – Diaa Abidou Mar 15 '11 at 21:01
@Diaa; see example – Herbert Mar 15 '11 at 21:39