18

I am using the fancyhdr package and I want to have a thicker line under my header and I want to have it colored, but my problem is, that this 2 commands:

\renewcommand{\headrule}{\vbox to 0pt{\hbox
to\headwidth{\textcolor{headercolor}{\hrulefill}}\vss}} 
\renewcommand{\headrulewidth}{2pt}

Do not work together? So how can I get a more thicker line which is also colored?

Here is the complete 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} 

\usepackage{xcolor,bookmark}
\usepackage{scrextend}
\usepackage{titlepic}
\usepackage{shorttoc}
\usepackage{courier}
%\usepackage{titlesec}
%\usepackage[titles]{tocloft}

\usepackage{type1cm}         
\usepackage{zref-abspage}



    \usepackage{makeidx}        

    \usepackage{graphicx}                                         
  \usepackage{multicol}       
   \usepackage{thmbox}
    \usepackage{shadethm}
    \usepackage{amsthm}
    \usepackage{amsmath}
    \usepackage{marginnote}
    %\usetocstyle{KOMAlike}
    \usepackage{wrapfig}
    \usepackage{paralist}
    \usepackage{amssymb}
    \usepackage[framemethod=tikz]{mdframed}
    \usepackage{ulem}
    \usepackage{fancyheadings}
    %\usepackage{sectsty}

    \definecolor{headercolor}{rgb}{0.6941,0.6745,0.4863}


    \begin{document}

\mainmatter%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\include{part1} 
\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{ \textcolor{headercolor}\leftmark \text{ }\textcolor{headercolor}{\thesection}}
\fancyhead[R]{\textcolor{headercolor}{\thepage}}
%\renewcommand{\headrule}{\vbox to 0pt{\hbox
%to\headwidth{\textcolor{headercolor}{\hrulefill}}\vss}} 
\renewcommand{\headrulewidth}{2pt}
 test test\\ test test    

\end{document}
2
  • 3
    Don't sent "complete code" which includes files we don't have. Sent a small example that we can compile and so use for tests. Also use fancyhdr instead of fancyheadings which is obsolete. Sep 3, 2012 at 15:05
  • I now merged your two accounts together. You should be able to edit your question again and comment to answers to it. Please consider registering an account to avoid this hassle in the future. Or, at least, try to keep one unregistered account (Cookies enabled?). Sep 3, 2012 at 17:19

1 Answer 1

27

You need to incorporate \headrulewidth inside your redefinition of \headrule, since \hrulefill uses a different width rule:

\renewcommand{\headrulewidth}{2pt}% 2pt header rule
\renewcommand{\headrule}{\hbox to\headwidth{%
  \color{headercolor}\leaders\hrule height \headrulewidth\hfill}}

Here's an informal MWE that uses the above technique to construct the page style myheader:

enter image description here

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\usepackage{fancyhdr}% http://ctan.org/pkg/fancyhdr
\fancypagestyle{myheader}{%
  \fancyhf{}% Clear all headers/footers
  \fancyhead[C]{My header}% Header Centred
  \fancyfoot[C]{-\thepage-}% Footer Centred
  \renewcommand{\headrulewidth}{2pt}% 2pt header rule
  \renewcommand{\headrule}{\hbox to\headwidth{%
    \color{red}\leaders\hrule height \headrulewidth\hfill}}
  \renewcommand{\footrulewidth}{0pt}% No footer rule
}
\setlength{\headheight}{21pt}%
\begin{document}
\pagestyle{myheader}
\lipsum[1-20]
\end{document}
2
  • Thanks, Werner! Can I also have the text in the header ('My header') to be on the header line directly, instead of being vertically centered in the header? I think this is due, to the created \hbox if I'm not mistaken?? Thanks
    – mt1111
    Nov 27, 2015 at 15:36
  • 1
    @marinko: I suggest trying something like \fancyhead[C]{\raisebox{-.5\baselineskip}[0pt][0pt]{My header}}. This lowers the My header 1/2 a baseline skip and completely removes the depth/height of the resulting change (to avoid any possible warnings in your .log).
    – Werner
    Nov 27, 2015 at 15:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .