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:

\geometry{left=4cm,right=3cm, top=2cm, bottom=2cm} 
\titleformat{\chapter}[display]{\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}
%  pdfauthor={},
  pdfsubject={Statistics Book}, 





\marginparsep = -4pt





\addcontentsline{toc}{part}{\"Uber den Autor}
  • 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.
    – raphink
    Sep 3 '12 at 15:10

First, you need to replace the line




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:

\headrule \sethead[\thepage][][\color{red} \chaptertitlename\ \thechapter. \chaptertitle]
{\color{red} \thesection\ \sectiontitle}{}{\thepage}}

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

\headrule \sethead[\thepage][][\color{red} \thesection\ \sectiontitle]
{\color{red} \thesection\ \sectiontitle}{}{\thepage}}

This should look like what you are expecting.

  • 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.