Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Possible Duplicate:
Header, footer and font customization

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}
%\usepackage[hidelinks,bookmarks=true,bookmarksopen=true,bookmarksnumbered=true,colorlinks=true,linkcolor=black,]{hyperref}
\usepackage[colorlinks,linkcolor=black,bookmarksopen=false,
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{shadethm}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{marginnote}
\usepackage{wrapfig}
\usepackage{paralist}
\usepackage{amssymb}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{ulem}

\definecolor{shadethmcolor}{rgb}{.9,.9,.95}%

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

\theoremstyle{mystyle}

\newmdtheoremenv[hidealllines=true,backgroundcolor=shadethmcolor,skipabove=\topsep,
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
\addcontentsline{toc}{part}{Index}
\printindex

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\cleardoublepage
\phantomsection
\addcontentsline{toc}{part}{\"Uber den Autor}
\includepdf{ueberautor}
\includepdf{back}
\end{document}
share|improve this question

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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
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

1 Answer 1

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}{
\headrule \sethead[\thepage][][\color{red} \chaptertitlename\ \thechapter. \chaptertitle]
{\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}{
\headrule \sethead[\thepage][][\color{red} \thesection\ \sectiontitle]
{\color{red} \thesection\ \sectiontitle}{}{\thepage}}
\pagestyle{mystyle2}

This should look like what you are expecting.

share|improve this answer
    
mh, it does not work, I get the error message ! LaTeX Error: Option clash for package titlesec. –  HFDuser Sep 3 '12 at 15:31
    
ok, now it does work. But I also want to have the line under it more thicker and colored and also the page number colored, how can I do this? –  HFDuser Sep 3 '12 at 15:36
    
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
    
and how can I get the line under it more thicker and colored? Thanks –  HFDuser Sep 3 '12 at 18:02
    
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

Not the answer you're looking for? Browse other questions tagged or ask your own question.