6

My goal is to realize this layout for a book (possibly using fancyhdr, but I'm open to everything):

enter image description here

where the current layout is represented in grey. In other words, I want :

  • to put the page numbering on the footer of each page (except part title pages)
  • to put the name of the current part on even (non-special) pages (with the format shown in the picture: PART I: XXX) + a line under it
  • to put the name of the current chapter on odd (non-special) pages (with the format shown in the picture: CHAPTER I: XXX) + a line under it

What I name "special pages" are the pages of part title or the first page of each chapter.

  1. How to do that?
  2. From a professional editor point of view, what alignments should I choose for the header on even pages (part title on the left/center/right?) and for the header on odd pages (chapter title on the left/center/right?) (is there a prefered/more "natural" alignment?)

Here is an example of a basic document:

\documentclass[11pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{hyperref}
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{fancyhdr}
\usepackage{lipsum}

%Note: this is a very preliminary attempt..., 
%Fancier solutions are welcome
%The page numbering does not work correctly
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{1pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhead[LE]{\thepart} %How do I get the part name in capital letters
\fancyhead[RO]{\thechapter} %How do I get the chapter name in capital letters

\begin{document}
\mainmatter

\part{Premiere partie}
\chapter{Premier chapitre}
\lipsum
\lipsum
\lipsum
\lipsum
\chapter{Second chapitre}
\lipsum
\lipsum
\lipsum
\lipsum
\part{Deuxieme partie}
\chapter{Troisieme chapitre}
\lipsum
\lipsum
\lipsum
\lipsum
\chapter{Quatrieme chapitre}
\lipsum
\lipsum
\lipsum
\lipsum

\end{document}
4
  • Please provide a minimal example (or see here). Otherwise people may well guess the wrong class and so forth. Regarding placement, I usually incline to centering headers and footers for "two-sided" documents.
    – jon
    May 1, 2015 at 23:58
  • Not setting the height of the header rule to 0pt would return you to the default which includes a rule for fancyhdr. What have you tried using fancyhdr? Have you tried anything? Nothing in your code even attempts to create the layout you describe.
    – cfr
    May 2, 2015 at 0:31
  • Also, why do you particularly want to use fancyhdr?
    – cfr
    May 2, 2015 at 0:35
  • @cfr: I changed the phrasing of the subject. Any other package is welcome. I added a very bad first guess too...
    – Vincent
    May 2, 2015 at 0:49

3 Answers 3

3

You can try with

\documentclass[11pt,a4paper]{book}

\usepackage[utf8]{inputenc}
%\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{hyperref}
\usepackage[head=15pt, top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{lipsum}

\newcommand*\parttitle{}
\let\origpart\part
\renewcommand*{\part}[2][]{%
\ifx\\#1\\% optional argument not present?
  \origpart{#2}%
  \renewcommand*\parttitle{#2}%
\else
  \origpart[#1]{#2}%
  \renewcommand*\parttitle{#1}%
\fi
}

\usepackage{fancyhdr}\pagestyle{fancy}
\fancyhead{}
\fancyhead[RO]{\leftmark}
\fancyhead[LE]{Partie \thepart: \parttitle}
\fancyfoot{}
\fancyfoot[C]{\thepage}

\begin{document}

\part{Premiere partie}
\chapter{Premier chapitre}
\lipsum
\lipsum
\lipsum
\lipsum
\chapter{Second chapitre}
\lipsum
\lipsum
\lipsum
\lipsum
\part{Deuxieme partie}
\chapter{Troisieme chapitre}
\lipsum
\lipsum
\lipsum
\lipsum
\chapter{Quatrieme chapitre}
\lipsum
\lipsum
\lipsum
\lipsum

\end{document}

You must edit the font style in \fancyhead[RO]{\leftmark} and \fancyhead[LE]{Partie \thepart: \parttitle}. Moreover, you maybe need works with \thispagestyle{empty} for white pages before new chapter and new part.

I put % before \usepackage[T1]{fontenc} due problems with online latex compiler. Also

14
  • You should not set \headheight manually in a document which uses geometry as it will throw geometry's calculations. Instead, tell geometry that's what you want.
    – cfr
    May 2, 2015 at 3:41
  • With online latex compiler appears warnning message related \headheight : " Package Fancyhdr Warning: \headheight is too small (12.0pt): Make it at least 13.59999pt."
    – juanuni
    May 3, 2015 at 17:52
  • Yes. You need to add headheight=15pt or whatever to the settings you pass geometry.
    – cfr
    May 3, 2015 at 19:50
  • If I make %\setlength{\headheight}{15pt} in the document, appears the warnning message ... regards
    – juanuni
    May 3, 2015 at 19:55
  • Yes. You should add it to the options for geometry.
    – cfr
    May 3, 2015 at 19:57
1

The following will do what you say you want. I am not sure it is what you want, but your mileage may vary.

\pagestyle{fancy}
\fancyhf{}
\fancyhf[coh]{\rightmark}
\fancyhf[ceh]{\leftmark}
\fancyhf[cf]{\thepage}
\renewcommand\chaptermark[1]{\markright{\MakeUppercase{\chaptername{} \thechapter: #1}}}
\makeatletter
\def\@part[#1]#2{%
    \ifnum \c@secnumdepth >-2\relax
      \refstepcounter{part}%
      \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
    \else
      \addcontentsline{toc}{part}{#1}%
    \fi
    \markboth{\MakeUppercase{\partname{} \thepart: #1}}{}%
    {\centering
     \interlinepenalty \@M
     \normalfont
     \ifnum \c@secnumdepth >-2\relax
       \huge\bfseries \partname\nobreakspace\thepart
       \par
       \vskip 20\p@
     \fi
     \Huge \bfseries #2\par}%
    \@endpart}
\makeatother

part and chapter

Complete code:

\documentclass[11pt,a4paper,french]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{fancyhdr}
\usepackage{lipsum}

\pagestyle{fancy}
\fancyhf{}
\fancyhf[coh]{\rightmark}
\fancyhf[ceh]{\leftmark}
\fancyhf[cf]{\thepage}
\renewcommand\chaptermark[1]{\markright{\MakeUppercase{\chaptername{} \thechapter: #1}}}
\makeatletter
\def\@part[#1]#2{%
    \ifnum \c@secnumdepth >-2\relax
      \refstepcounter{part}%
      \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
    \else
      \addcontentsline{toc}{part}{#1}%
    \fi
    \markboth{\MakeUppercase{\partname{} \thepart: #1}}{}%
    {\centering
     \interlinepenalty \@M
     \normalfont
     \ifnum \c@secnumdepth >-2\relax
       \huge\bfseries \partname\nobreakspace\thepart
       \par
       \vskip 20\p@
     \fi
     \Huge \bfseries #2\par}%
    \@endpart}
\makeatother
\begin{document}
  \mainmatter

  \part{Premiere partie}
  \chapter{Premier chapitre}
  \lipsum
  \lipsum
  \lipsum
  \lipsum

\end{document}

EDIT

The reason I'm not sure the above is what you want is because I think it looks peculiar when there is an empty page between chapters. You may disagree but, if not, you can eliminate them if you wish.

If you don't want headers on pages between chapters, but do want a page number, add

\usepackage{etoolbox,nextpage}
\patchcmd{\chapter}{\cleardoublepage}{\cleartooddpage[\thispagestyle{plain}]}{\typeout{Chapters successfully patched for no headers on pages between chapters.}}{\typeout{Could not patch chapters to eliminate headers on pages between chapters.}}

If you don't want a page number either, change plain to empty.

My personal view, by the way, is that these headers are much too heavy and distracting. They are underlined, in all capitals and bang centre. I would recommend a more subtle approach which provides information without drawing the eye away from the content of the text. (Drop the rule or move the header to one side or the other and get rid of the capitalisation or....)

1

You can patch \part to issue \partmark instead of \markboth{}{}, similarly to how \chapter issues \chaptermark. Then it's just a matter of defining suitably those two macros.

\documentclass[11pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage[top=1in, bottom=1in, left=1in, right=1in, headheight=13.6pt]{geometry}
\usepackage{fancyhdr}
\usepackage{etoolbox}
\usepackage{hyperref}



\usepackage{lipsum}

%Note: this is a very preliminary attempt..., 
%Fancier solutions are welcome
%The page numbering does not work correctly
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{1pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhead[LE]{\leftmark}
\fancyhead[RO]{\rightmark}

\begingroup\lccode`~=`:
\lowercase{\endgroup
  \newcommand{\partmark}[1]{%
    \markboth{\MakeUppercase{\partname\space\thepart~ #1}}{}%
  }
  \renewcommand{\chaptermark}[1]{%
    \markright{\MakeUppercase{\chaptername\space\thechapter~ #1}}%
  }
}% end of \lowercase
\makeatletter
\patchcmd{\H@old@part}% would be \@part without hyperref
  {\markboth{}{}}
  {\partmark{#1}}
  {}{}
\makeatother

\begin{document}
\mainmatter

\part{Premiere partie}
\chapter{Premier chapitre}
\lipsum
\lipsum
\lipsum
\lipsum
\chapter{Second chapitre}
\lipsum
\lipsum
\lipsum
\lipsum
\part{Deuxieme partie}
\chapter{Troisieme chapitre}
\lipsum
\lipsum
\lipsum
\lipsum
\chapter{Quatrieme chapitre}
\lipsum
\lipsum
\lipsum
\lipsum

\end{document}

Note that a peculiar trick is needed in order to get the French colon in the headers. Basically, \partmark and \chaptermark are defined with an active version of the colon.

Since we do the patch after loading hyperref, we need to patch \H@old@part instead of `\@part.

Don't neglect the warning by fancyhdr about the head height; I added the suggested setting to the options for geometry.

enter image description here

You must log in to answer this question.

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