I'm looking for a more fancy alternative to the default (read boring) horizontal line produced under the fancyhdr package. How creative can we get?

up vote 19 down vote accepted

Here are five possibilities: two rules (one below, one above); a double colored rule below; a "rule" made with a pattern produced with the help of pgfornament; a colored rounded box, and a colored frame (the last two produced with TikZ). To produce the header, I used the titleps package, but fancyhdr could've been used instead:

\documentclass[draft]{article}
\usepackage[a6paper]{geometry}% just for the example
\usepackage[object=vectorian]{pgfornament}
\usepackage{tikzpagenodes}
\usepackage{titleps}
\usepackage{lipsum}

\newpagestyle{mystyle}{
  \sethead{}{\thesection~\sectiontitle}{\thepage}\headrule
}
\pagestyle{mystyle}

\newcommand\myrule{%
  \leavevmode\cleaders\hbox{\raisebox{-2.5pt}{\pgfornament[width=0.2\textwidth]{88}}}\hfill\kern0pt}

\begin{document}

\renewcommand\makeheadrule{\color{red!70!black}%
  \makebox[0pt][l]{%
    \rule[.8\baselineskip]{\linewidth}{0.8pt}}%
    \rule[-.3\baselineskip]{\linewidth}{0.8pt}%
}
\section{Test Section}
\lipsum[4]\lipsum[4]

\clearpage
\renewcommand\makeheadrule{\color{red!70!black}%
  \makebox[0pt][l]{%
    \rule[-.3\baselineskip]{\linewidth}{0.4pt}}%
    \rule[-.4\baselineskip]{\linewidth}{0.4pt}%
}
\section{Test Section}
\lipsum[4]\lipsum[4]

\clearpage
\renewcommand\makeheadrule{\myrule}
\section{Test Section}
\lipsum[4]\lipsum[4]

\clearpage
\renewcommand\makeheadrule{%
\begin{tikzpicture}[remember picture,overlay]
  \draw[cyan,thick,rounded corners=5pt] 
  ([xshift=-3pt]current page header area.north west) 
    rectangle
  ([xshift=2pt,yshift=-3pt]current page header area.south east);
\end{tikzpicture}}
\section{Test Section}
\lipsum[4]\lipsum[4]

\clearpage
\renewcommand\makeheadrule{%
\begin{tikzpicture}[remember picture,overlay]
  \fill[orange] 
  (current page.north west) 
    rectangle
  ([xshift=2pt,yshift=-3pt]current page.east|-current page header area.south east);
\end{tikzpicture}}
\section{Test Section}
\lipsum[4]\lipsum[4]

\end{document}

enter image description here

And some other examples, mostly to show possibilities:

\documentclass[draft]{article}
\usepackage[a6paper]{geometry}% just for the example
\usepackage{tikzpagenodes}
\usepackage{titleps}
\usepackage{lipsum}
\usetikzlibrary{shapes.symbols}

\newpagestyle{mystyleii}{
  \sethead{}{{\begin{tikzpicture}
    \node[draw=olive,rectangle,fill=olive!30,text width=.5\textwidth,inner xsep=0pt,align=center] at (current page header area.center) (header) {\thesection~\sectiontitle};
  \end{tikzpicture}}}{}
  \setfoot{}{{\begin{tikzpicture}
  \node[draw=olive,rectangle,fill=olive!30,text width=3em,inner xsep=0pt,align=center] at (current page footer area.center) {\thepage};
  \end{tikzpicture}}}{}
}
\pagestyle{mystyleii}


\begin{document}

\section{Test Section}
\lipsum[4]\lipsum[4]

\clearpage
\newpagestyle{mystyleiii}{
  \sethead{}{{\begin{tikzpicture}
    \node[draw=none,rectangle,left color=olive!40,right color=orange!40,text width=.5\textwidth,inner xsep=0pt,align=center] at (current page header area.center) (header) {\thesection~\sectiontitle};
  \end{tikzpicture}}}{}
  \setfoot{}{{\begin{tikzpicture}
  \node[draw=none,rectangle,left color=olive!40,right color=orange!40,text width=3em,inner xsep=0pt,align=center] at (current page footer area.center) {\thepage};
  \end{tikzpicture}}}{}
}
\pagestyle{mystyleiii}
\section{Test Section}
\lipsum[4]\lipsum[4]

\clearpage
\addtolength\headheight{29pt}
\newpagestyle{mystyleiv}{
  \sethead{}{{\begin{tikzpicture}
    \node[draw=none,starburst,line width=2pt,draw=red,fill=yellow!40,text width=.5\textwidth,inner xsep=0pt,align=center] at (current page header area.center) (header) {\thesection~\sectiontitle};
  \end{tikzpicture}}}{}
  \setfoot{}{{\begin{tikzpicture}
  \node[draw=none,starburst,line width=2pt,draw=red,fill=yellow!40,text width=3em,inner xsep=0pt,align=center] at (current page footer area.center) {\thepage};
  \end{tikzpicture}}}{}
}
\pagestyle{mystyleiv}
\section{Test Section}
\lipsum[4]\lipsum[4]

\end{document}

enter image description here

Some other possibility, using now the "torn page" decoration developed by JLDiaz in his answer to Torn page effect:

\documentclass[draft]{article}
\usepackage[a6paper]{geometry}% just for the example
\usepackage{tikzpagenodes}
\usepackage{titleps}
\usepackage{lipsum}
\usetikzlibrary{decorations.pathmorphing,calc,shadows.blur,shadings}
\pgfmathsetseed{1}

\pgfdeclaredecoration{irregular fractal line}{init}
{
  \state{init}[width=\pgfdecoratedinputsegmentremainingdistance]
  {
    \pgfpathlineto{\pgfpoint{random*\pgfdecoratedinputsegmentremainingdistance}{(random*\pgfdecorationsegmentamplitude-0.02)*\pgfdecoratedinputsegmentremainingdistance}}
    \pgfpathlineto{\pgfpoint{\pgfdecoratedinputsegmentremainingdistance}{0pt}}
  }
}

\tikzset{
   paper/.style={draw=black!10, blur shadow, shade=bilinear interpolation,
                 lower left=black!20, upper left=black!15, upper right=white, lower right=black!10},
   irregular border/.style={decoration={irregular fractal line, amplitude=0.2},
           decorate,
     },
   ragged border/.style={ decoration={random steps, segment length=7mm, amplitude=2mm},
           decorate,
   }
}

\newpagestyle{mystylev}{
  \sethead{}{\thesection~\sectiontitle}{\thepage}\headrule
  \setfoot{}{}{}
}
\pagestyle{mystylev}
\renewcommand\makeheadrule{%
\begin{tikzpicture}[remember picture,overlay]
  \fill[red!30!cyan!60]
        decorate[irregular border]{decorate{decorate{decorate{decorate[ragged border]{
        ($(current page header area.south east-|current page.east) - (0, random*30mm)$) -- ($(current page header area.south west-|current page.west) - (0, random*12mm)$)
        }}}}}
        -- (current page.north west) -- (current page.north east) -- cycle;
\end{tikzpicture}
}

\begin{document}

\section{Test Section}
\lipsum[4]\lipsum[4]

\end{document}

enter image description here

  • +1 for the last one. It doesn't fit anywhere, but where it fits it does it perfectly. I like it so much. – Manuel May 12 '13 at 23:34

an example with simple boxes. You could also use tikz or pgf commands for more sophisticated headers:

\documentclass[fleqn,11pt,pdflatex]{book}
\usepackage{microtype}
\usepackage{times}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage{calc}
\usepackage{xcolor}

\usepackage{fancyhdr}%
\pagestyle{fancy}%
\setlength\fboxsep{1pt}
\setlength\fboxrule{1pt}
\fancyhf{}%
\fancyfoot[LO]{\colorbox{red}{\makebox[1cm]{\thepage}}\mbox{\hskip2pt}\colorbox{black!5}{\makebox[\linewidth-2cm-4pt-4\fboxrule-4\fboxsep]{\leftmark}}\mbox{\hskip2pt}\colorbox{blue}{\makebox[1cm]{\thesection}}}%
\fancyfoot[RE]{\colorbox{red}{\makebox[1cm]{\thepage}}\colorbox{black!5}{\makebox[\linewidth-2cm-4pt-4\fboxrule-4\fboxsep]{\rightmark}}\colorbox{blue}{\makebox[1cm]{\thesection}}}%
\begin{document}
\chapter{chapter}
\section{section a}
\lipsum[1-10]
\section{section b}
\lipsum[1-10]
\section{section c}
\lipsum[1-10]

which yields:

enter image description here

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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