Possible Duplicate:

I am writing on a larger project (a book) and I now there are lots of possibilities about headers. But I am a newbie and I do not know which is perhaps the best, so I wanted to ask you how I should implement a header in the best way? I want the header to display the page number and the section title and also there should be a line under it. I do not know how to implement this, also the page number which is now under the text should disappear and the text in the header should have a color, but the page number should be black. The line should be a little more than maybe 4 pt thick. Thanks a lot for your help! Here is my code:

\documentclass{book}
\usepackage{geometry}
\geometry{left=4cm,right=3cm, top=2cm, bottom=2cm}
\usepackage{titlesec}
\titlespacing*{\chapter}{0pt}{-30pt}{20pt}
\titleformat{\chapter}[display]{\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}
\usepackage[ngerman]{babel}
\usepackage{mathptmx}
\usepackage{helvet}
\usepackage{wallpaper}
\usepackage{color}
\usepackage[final]{pdfpages}
%,bookmarksopenlevel={1}
hypertexnames=TRUE,pdfpagelabels=true]{hyperref}[2011/02/05]
\hypersetup{
pdftitle={},
%  pdfauthor={},
pdfsubject={Statistics Book},
pdfkeywords={},
}
\usepackage{xcolor,bookmark}
\usepackage{scrextend}
\usepackage{titlepic}
\usepackage{shorttoc}
\usepackage{courier}
\usepackage{type1cm}
\usepackage{zref-abspage}
\usepackage{makeidx}
\usepackage{graphicx}
\usepackage{multicol}
\usepackage[bottom]{footmisc}
\usepackage{tocstyle}
\usetocstyle{allwithdot}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{marginnote}
\usepackage{wrapfig}
\usepackage{paralist}
\usepackage{amssymb}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{ulem}

\newtheoremstyle{mystyle}
{\topsep}{\topsep}{}{}%
{\bfseries}{:}{.5em}{}%

\theoremstyle{mystyle}

skipbelow=\topsep]{example}{example}

\begin{document}
\frontmatter%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\setlength{\marginparwidth}{2.1cm}
\marginparsep = -4pt
\pagestyle{plain}
\pagenumbering{Roman}
\include{dedic}
\newpage\section*{}
\include{foreword}
\newpage\section*{}
\include{preface}
\newpage\section*{}
\include{acknow}
\newpage\section*{}
\include{acronym}
%
\
\shorttableofcontents{Inhalts\"ubersicht}{1}
\bookmark[page=15,rellevel=1,keeplevel,view={XYZ},color=red]{Inhalts\"ubersicht}
\bookmark[page=17,rellevel=1,keeplevel,view={XYZ},color=red]{Inhaltsverzeichnis}
\tableofcontents
\clearpage
\pagenumbering{arabic}
%

\mainmatter%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\include{part1}
\include{chapter1}
\include{chapter2}
\include{chapter3}
\include{part2}
\include{chapter4}
\include{chapter5}
\include{chapter6}
\backmatter

\appendix

\include{appendix}

\listoffigures
\newpage
\listoftables
\backmatter%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\include{glossary}
%\include{solutions}
\cleardoublepage
\phantomsection
\printindex

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\cleardoublepage
\phantomsection
\includepdf{ueberautor}
\includepdf{back}
\end{document}

-

## marked as duplicate by Tom Bombadil, percusse, Claudio Fiandrino, Martin Schröder, diabonasSep 10 '12 at 10:55

As you seem to be using the titlesec package already, the \newpagestyle command should fit your needs (you also need to provide the option pagestyles when loading the titlesec package). The titlesec manual explains how to use it with nice examples (see in particular page 12). – Corentin Sep 3 '12 at 14:21
mh, that does not help me, because I also do not know what to do with \newpagestyle? – HFDuser Sep 3 '12 at 14:29
Ok, I have just given a more detailed answer. Still, it may be worth reading the titlesec manual to get more information on how to use these commands and examples of what they can do. – Corentin Sep 3 '12 at 15:03
Note also that there are other book classes that include such functionalities, such as memoir and scrbook. – ℝaphink Sep 3 '12 at 15:10

First, you need to replace the line

\usepackage{titlesec}


with

\usepackage[pagestyles]{titlesec}


to make the command \newpagestyle available. Then you can create your own header and footer style with this command with the syntax: \newpagestyle{stylename}[global style options]{commands}. The "commands" argument may include other commands such as \headrule to include an horizontal line under the header (as you seem to wish) or \sethead to customize the contents of the headers. The syntax is \sethead[even-left][even-center][even-right]{odd-left}{odd-center}{odd-right}.

For instance, you can create the style "mystyle" by adding the following lines:

\newpagestyle{mystyle}{
{\color{red} \thesection\ \sectiontitle}{}{\thepage}}
\pagestyle{mystyle}


If you are only interested in the section title and not the chapter (although you are using the book class), you can try

\newpagestyle{mystyle2}{

If you want the page number to be colored also, you can move the \color{red} out of the \sethead command and put it in the global style options in the \newpagestyle command. – Corentin Sep 3 '12 at 16:03
About the color, my previous comment does not seem to work for the headrule, but regarding the thickness, you can simply add a \setheadrule{length} command (the default length being .4pt). – Corentin Sep 3 '12 at 20:40