Page Layoutchapter name in header

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
komal
Posts: 14
Joined: Thu Jun 02, 2011 1:57 pm

Re: chapter name in header

Post by komal »

so how do I set the same margin for both odd and even pages?

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

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

chapter name in header

Post by localghost »

komal wrote:[…] I have set the margin using the command
\usepackage[top=1.5in, bottom=1in, left=1.5in, right=1in]{geometry}
in the previously posted code but it gives an error saying
Error: Option clash for package geometry.
As I already said, the package has already been included without options. So don't load it twice. Try this.

Code: Select all

\documentclass[11pt,a4paper,oneside,openany,english]{book}
\usepackage{etoolbox}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[includehead,nofoot,top=1.5in,bottom=1in,left=1.5in,right=1in]{geometry}
\usepackage[pagestyles,raggedright]{titlesec}
\usepackage{blindtext}

\author{Komal}
\title{The Title of the Document}

\makeatletter
\let\Title\@title
\let\Author\@author
\makeatother

\newpagestyle{front}{%
  \sethead{\ifnumodd{\value{page}}{\Title}{\chaptertitle}}{}{\thepage}
  \headrule
}
\newpagestyle{main}{%
  \sethead{\ifnumodd{\value{page}}{\Title}{\thechapter\enspace\chaptertitle}}{}{\thepage}
  \headrule
}
\newpagestyle{back}{%
  \sethead{\ifnumodd{\value{page}}{\Title}{\chaptertitle}}{}{\thepage}
  \headrule
}
\assignpagestyle{\chapter}{empty}

\begin{document}
  \maketitle
    
  \frontmatter
	\pagestyle{front}
  \tableofcontents
  \listoffigures
  \listoftables

  \mainmatter	
  \pagestyle{main}
  \blinddocument
	
  \appendix
  \blinddocument
	
  \backmatter
  \pagestyle{back}
  \begin{thebibliography}{9}
    \bibitem{key} Bibliography Item
  \end{thebibliography}
\end{document}
I added the etoolbox package which provides a mechanism to check whether the current page number value is odd or even. This is then used for the header setup.

In case you still prefer the version with the »report« class, you can try this.

Code: Select all

\documentclass[11pt,a4paper,english]{report}
\usepackage{etoolbox}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[includehead,nofoot,top=1.5in,bottom=1in,left=1.5in,right=1in]{geometry}
\usepackage[pagestyles,raggedright]{titlesec}
\usepackage{blindtext}

\author{Komal}
\title{The Title of the Document}

\makeatletter
\let\Title\@title
\let\Author\@author
\makeatother

\newpagestyle{front}{%
  \sethead{\ifnumodd{\value{page}}{\Title}{\chaptertitle}}{}{\thepage}
	\headrule
}
\newpagestyle{main}{%
  \sethead{\ifnumodd{\value{page}}{\Title}{\thechapter\enspace\chaptertitle}}{}{\thepage}
	\headrule
}
\newpagestyle{back}{%
  \sethead{\ifnumodd{\value{page}}{\Title}{\chaptertitle}}{}{\thepage}
	\headrule
}
\assignpagestyle{\chapter}{empty}

\begin{document}
  \pagenumbering{roman}
  \maketitle
    
  \pagestyle{front}
  \tableofcontents
  \listoffigures
  \listoftables

  \pagenumbering{arabic}	
  \pagestyle{main}
  \blinddocument
	
  \appendix
  \blinddocument

  \pagestyle{back}
  \begin{thebibliography}{9}
    \bibitem{key} Bibliography Item
  \end{thebibliography}
\end{document}
komal
Posts: 14
Joined: Thu Jun 02, 2011 1:57 pm

Re: chapter name in header

Post by komal »

Thank you so much. The code works perfectly fine now. This forum has been a great help. :)
Post Reply