4

I need to reproduce the following header format:

enter image description here

\documentclass{book}
\usepackage{fancyhdr}    
\pagestyle{fancy}
\cfoot{}
\lhead{\thepage}

3 Answers 3

4

The scrpage2 package (part of KOMA-Script) offers the headtoprule option.

\documentclass{book}

\usepackage[automark,headtopline,headsepline,nouppercase]{scrpage2}
\pagestyle{scrheadings}
\clearscrheadfoot
\ihead{\headmark}% use \leftmark to display only chapters
\ohead{\pagemark}

\usepackage{lipsum}

\begin{document}

\chapter{A chapter}

\section{A section}

\lipsum[1-12]

\end{document}

If you want this page style also to apply for chapter-starting pages, use the following preamble code:

\documentclass{book}

\usepackage[automark,headtopline,headsepline,plainheadtopline,plainheadsepline,nouppercase]
    {scrpage2}
\pagestyle{scrheadings}
\clearscrheadfoot
\ihead[\firstmark]{\headmark}
\ohead[\pagemark]{\pagemark}

For the report class (or book with oneside), replace \firstmark with \headmark.

Finally, here's the preamble code for a header that doesn't switch between left and right pages in twoside mode:

\documentclass{book}

\usepackage[automark,headtopline,headsepline,nouppercase]{scrpage2}
\pagestyle{scrheadings}
\clearscrheadfoot
\lehead{\leftmark}
\lohead{\leftmark}
\rehead{\pagemark}
\rohead{\pagemark}
4
  • Thanks. How can we apply this format to all pages? without relocation
    – Angel
    Jul 15, 2013 at 12:51
  • @Angel I'm not sure what you mean with "relocation" -- I hope my updated answer helps.
    – lockstep
    Jul 15, 2013 at 13:01
  • I wanna chapter name is on the left and page number is on the right.
    – Angel
    Jul 15, 2013 at 13:13
  • @Angel That's unusual for twoside mode (books default); answer updated again.
    – lockstep
    Jul 15, 2013 at 13:18
3

Simply redefine \headrule (no information was provides for the headers on odd-numbered pages, so I used the same settings, but this is easily modifiable):

\documentclass{book}
\usepackage[a6paper]{geometry}
\usepackage{fancyhdr}
\usepackage{lipsum}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{\small\sffamily\nouppercase\leftmark}
\fancyhead[R]{\small\sffamily\thepage}
\renewcommand\headrule{\vskip-1.7\headheight\hrulefill\vskip2pt\hrulefill}
\setlength\headheight{13pt}

\begin{document}

\chapter{Test chapter}
\lipsum[1-7]

\end{document}

enter image description here

To apply the same header to all pages (as requested in a comment to other answer) redefine the plain style to be fancy:

\documentclass{book}
\usepackage[a6paper]{geometry}
\usepackage{fancyhdr}
\usepackage{lipsum}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{\small\sffamily\nouppercase\leftmark}
\fancyhead[R]{\small\sffamily\thepage}
\renewcommand\headrule{\vskip-1.7\headheight\hrulefill\vskip2pt\hrulefill}
\setlength\headheight{13pt}
\makeatletter
\let\ps@plain\ps@fancy
\makeatother

\begin{document}

\chapter{Test chapter}
\lipsum[1-7]

\end{document}

enter image description here

0
1

You can get the lower line from the default value of \headrulewidth, which is 0.4pt. As for the upper line, insert your own \hrule:

\lhead{\hrule\vspace{2pt}\thepage}

The \vspace is there to prevent the \hrule being too close to the page number; you can adjust the value to your liking.

The layout for the image is

\renewcommand{\sectionmark}[1]{\markleft{\MakeLowercase{\chaptername\ \thechapter. #1}}}
\lhead{\hrule\vspace{2pt}\sffamily\chaptermark}
\rhead{\thepage}
1
  • The second code is not correct.
    – Angel
    Jul 15, 2013 at 12:25

You must log in to answer this question.

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