0

I need to display chapter title on even-numbered pages and section title on odd-numbered pages for one side document. I easily could get that for two side document. But for one side document, it either displays chapter title or section title on all pages, but not both on alternate pages. I have tried by the code shown below.

\documentclass[a4paper,12pt,oneside]{book}

\usepackage{fancyhdr}

\usepackage{lipsum}

\begin{document}

\pagestyle{fancy}


\fancyhf{}

\renewcommand{\chaptermark}[1]{\markboth{#1}{}}

\renewcommand{\sectionmark}[1]{\markright{#1}{}}

\lhead[E]{\leftmark}

\lhead[O]{\rightmark}

\cfoot{\thepage}

\lipsum

\lipsum

\end{document}
1
  • 1
    A oneside documenta does not have left and right pages. What you want does not make sense.
    – Johannes_B
    Jan 30 '18 at 7:28
1

How's this:

\documentclass[a4paper,12pt,oneside]{book}
\usepackage{fancyhdr}
\usepackage{lipsum}

\pagestyle{fancy}

\renewcommand{\chaptermark}[1]{\def\thechaptername{#1}}
\renewcommand{\sectionmark}[1]{\def\thesectionname{#1}}

\lhead{\ifodd\thepage\thesectionname\else\thechaptername\fi}
\cfoot{\thepage}

\begin{document}
\chapter{One}
\section{First}
\lipsum
\lipsum
\section{Second}
\lipsum
\lipsum
\chapter{Two}
\section{twofer}
\lipsum
\end{document} 
1
  • It works perfectly.
    – ug chauhan
    Jan 30 '18 at 12:04
1

Suggestion:

\documentclass[a4paper,12pt,oneside]{book}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{#1}{}}
\fancyhead[L]{\ifodd\value{page}\rightmark\else\leftmark\fi}
\fancyfoot[C]{\thepage}

\usepackage{blindtext}% only for dummy text
\begin{document}
\blinddocument
\blinddocument
\end{document}

The definitions for header and footer should be done in the preamble.

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.