2

I am writing a document using book class and I'd like to implement the following:

a) The header of all even pages have the title of the respective chapter (and possibly also the number, I haven't made up my mind about this yet; but not "Chapter 2 - Some Math", just something like "2. Some Math"). Not in upper case though (which is the LaTeX default).

b) The header of all odd pages would have the title of the respective section (and, again, possibly its number). (To distinguish between section titles and page titles perhaps the former ones could be emphasised).

On even pages (titles) the header should be left align, and on odd pages (sections) the headers should be right aligned. I'd also like to have page numbers on the center of the footer.

Also, I would appreciate if someone could present a solution where all the pages (even and odd) would have a header as in a). Thank you in advance.

MWE:

\documentclass[11pt,a4paper]{book}
\usepackage[portuguese]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}

\begin{document}

 \chapter*{Some Math Stuff}   

 \chapter{More Math Stuff}

\end{document}
  • 1
    The package fancyhdr seems fit for your purpose. To get chapter name in header, see this: tex.stackexchange.com/questions/89914/… – Herr K. May 27 '14 at 18:02
  • And the page number where should it be? Where do you want the headers? To the left on even pages and to the right on odd pages? – Gonzalo Medina May 28 '14 at 3:29
  • @GonzaloMedina thank you for your relevant questions, I've edited the question accordingly! – essay May 28 '14 at 13:46
3

Here's one possibility using the fancyhdr package and a redefinition of \chaptermark and \sectionmark to produce the desired result (the code also has the necessary modifications in case you decide not to include the numbers for the sectional units); since no info was given in the question about the page number, I placed it in the header opposed to the corresponding mark but, of course, you can change as required:

\documentclass[11pt,a4paper]{book}
\usepackage[portuguese]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{fancyhdr}
\usepackage{lipsum}

\pagestyle{fancy}
\fancyhf{}
\renewcommand\headrulewidth{0pt}
\setlength\headheight{13.6pt}

\fancyhead[EL]{\leftmark}% chapter mark to the left on even pages 
\fancyhead[OR]{\rightmark}% chapter mark to the right on odd pages

\fancyhead[ER,OL]{\thepage}% page number to the left on odd pages and
%  to the right on even pages

% Chapters and section marks with the number
\renewcommand\chaptermark[1]{\markboth{\thechapter.\ \itshape #1}{}}
\renewcommand\sectionmark[1]{\markright{\thesection.\ #1}}

% Chapters and section marks without the number
%\renewcommand\chaptermark[1]{\markboth{\itshape #1}{}}
%\renewcommand\sectionmark[1]{\markright{#1}}

\begin{document}

\chapter{More Math Stuff}
\section{Test section for more math stuff}
\lipsum[1-20]

\end{document}
1

Here is a suggestion using scrlayer-scrpage which is part of the KOMA-Script bundle. If a chapter ends on an odd page the even interleaf page will be plain.

\documentclass[11pt,a4paper]{book}
\usepackage[portuguese]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
%
\usepackage[pagestyleset=KOMA-Script,automark]{scrlayer-scrpage}
\pagestyle{scrheadings}
\clearscrheadfoot
\ohead{\headmark}
\cfoot[\pagemark]{\pagemark}
\renewcommand\chaptermarkformat{\thechapter.\enspace}
\usepackage[cleardoublepage=plain]{scrextend}% plain interleaf pages
\setlength\headheight{13.6pt}
%
\usepackage{lipsum}% dummy text

\begin{document}
\tableofcontents
\chapter{Some Math Stuff}
\section{Test section}
\lipsum[1-20] 
\chapter{More Math Stuff}
\lipsum[1-20]
\section{Another test section}
\lipsum[1-10]
\end{document}

If the chapter should be in the header on odd and even pages:

\documentclass[11pt,a4paper]{book}
\usepackage[portuguese]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
%
\usepackage[pagestyleset=KOMA-Script]{scrlayer-scrpage}
\automark[chapter]{chapter}
\pagestyle{scrheadings}
\clearscrheadfoot
\ohead{\headmark}
\cfoot[\pagemark]{\pagemark}

\renewcommand\chaptermarkformat{\thechapter.\enspace}
\usepackage[cleardoublepage=plain]{scrextend}% plain interleaf pages
\setlength\headheight{13.6pt}
%
\usepackage{lipsum}% dummy text

\begin{document}
\tableofcontents
\chapter{Some Math Stuff}
\section{Test section}
\lipsum[1-20] 
\chapter{More Math Stuff}
\lipsum[1-20]
\section{Another test section}
\lipsum[1-10]
\end{document}

Edit: Now the page numbers are on all pages in the center of the footer.

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.