5

I want to make this header style: enter image description here

I read some questions about header style here, and then I tried to make the above style. I used the following codes:

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}

\renewcommand\headrule{
\begin{minipage}{1\textwidth}
\hrule width \hsize \kern 5mm \hrule width \hsize 
\end{minipage}}%

\lhead{\thepage \hspace{1cm} Section \thesection}

I get this: enter image description here

I don't know how to move these horizontal lines. Can anyone teach me a better method to make the header style in the first picture? Thank you!

5

You can use the left field in each page and fill it appropriately.

\documentclass{book}

\usepackage{fancyhdr}

\usepackage{lipsum} % for the example

\newcommand{\headerbox}[2]{%
  \begin{minipage}[b]{\textwidth}
    \hrule
    \vspace{4pt}%
    \makebox[\textwidth][#1]{#2}\par
    \vspace{4pt}%
    \hrule
  \end{minipage}%
}

\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\chaptermark}[1]{%
  \markboth{\MakeUppercase{\chaptername\ \thechapter\ \textbullet\ #1}}{}% 
}
\setlength{\headheight}{20pt}
\fancyhf{}
\fancyhead[LE]{% even pages, left field
  \headerbox{l}{%
    \thepage\qquad\leftmark
  }%
}
\fancyhead[LO]{% odd pages, left field
  \headerbox{r}{%
    \rightmark\qquad\thepage
  }%
}

\begin{document}

\mainmatter

\chapter{Thermodynamics}

\section{First law}

\lipsum[1-20]

\end{document}

enter image description here

|improve this answer|||||
5

You can use \rule Be aware that the two line are not made the same way : the under one is the separation between the header and the body of the page. see in the doc of the fancyhdr package: \headrulewidth

The over one is made by the \rule command.

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[frenchb]{babel}
\usepackage{fancyhdr}


\pagestyle{fancy}

\begin{document}
\fancyhf{}
\lhead{\rule{\linewidth}{1pt}\\\thepage \hspace{1cm} Section \thesection}


\section{Test 1}
Coucou


\end{document}

enter image description here

|improve this answer|||||
  • 3
    This does not work in all cases. If you \section doesn't fit on the page it's placed it and spills to the top of the following page, the section number will still be printed in the header. Understandable though, if the OP is using a "chapter" as reference in the header, these usually have a \clearpage preceding it, making their placement in the header more rigid. Perhaps the OP misused "chapter" to actually mean section. – Werner Sep 26 '16 at 16:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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