Page LayoutChapter on left Page and Section on right Page

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
AleCes
Posts: 286
Joined: Sat Nov 13, 2010 9:54 pm

Chapter on left Page and Section on right Page

Post by AleCes »

Hello everybody,

In a document like this:

Code: Select all

\documentclass[12pt,a4paper,openany,oneside]{book}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{fontspec}
\defaultfontfeatures{Mapping=tex-text}
\setmainfont{FreeSerif}
\usepackage{polyglossia}
 \setmainlanguage{english}
\usepackage{xunicode}
\usepackage{xltxtra}
\usepackage{bookmark}

\begin{document}

\chapter{bla}

\section{bla}

\section{bla}

\end{document} 
How can I get to customize fancyhdr so that I have chapter name on the header of left pages and section name on the header of right pages?

Thank you very much,
Last edited by AleCes on Fri May 31, 2013 11:52 pm, edited 2 times in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Chapter on left Page and Section on right Page

Post by Johannes_B »

I've been taking a look at the documentation of fancyhdr and found the following:

Code: Select all

\documentclass[12pt,a4paper,openany,oneside]{book}
\usepackage{fancyhdr.
\pagestyle{fancy}
\lhead{\leftmark}
\rhead{\rightmark}
\usepackage{fontspec}
\defaultfontfeatures{Mapping=tex-text}
\setmainfont{FreeSerif}
\usepackage{polyglossia}
\setmainlanguage{english}
\usepackage{xunicode}
\usepackage{xltxtra}
\usepackage{bookmark}
\usepackage{blindtext}
\begin{document}

\chapter{testchapter}
\blindtext[4]
\section{testsec1}
\blindtext[4]
\section{testsec2}
\blindtext[4]
\end{document}
You would have found the same by a little reading.

Your minimal working example was quite good, but the naming of your sections is terrible. You could have invested a little more phantasy.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
AleCes
Posts: 286
Joined: Sat Nov 13, 2010 9:54 pm

Chapter on left Page and Section on right Page

Post by AleCes »

OK, Johannes_B, so, now what about the answer?
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Chapter on left Page and Section on right Page

Post by Johannes_B »

Did you read my posted code? Copy and compile it.

Maybe you notice the commands for lhead and rhead.

EDIT: I just took another look at your initial question and I have a question. You are asking for a layout on right (odd) and left (even) pages, but you are defining a global option oneside. In this case, there are no even and odd pages. Also, the option openany is not really usefull in the case of oneside.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
AleCes
Posts: 286
Joined: Sat Nov 13, 2010 9:54 pm

Chapter on left Page and Section on right Page

Post by AleCes »

OK, sorry, I'm really sorry, I didn't notice the lhead command but I've compiled it and I see no changes in the header layout.

About oneside, just forget about it, in this document it's just a typo. Obviously I removed it before I compiled.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Chapter on left Page and Section on right Page

Post by Johannes_B »

Try the following:

Code: Select all

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{}
\fancyhead[LE]{\leftmark}
\fancyhead[RO]{\rightmark}
But remember to delete the option oneside.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
AleCes
Posts: 286
Joined: Sat Nov 13, 2010 9:54 pm

Re: Chapter on left Page and Section on right Page

Post by AleCes »

OK, thank you very much it works wonderfully! :o
Post Reply