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

chapter name in header

Post by komal »

The header will comprise the title of the report. On every odd page will appear the title of the report while on the even pages the title of the chapter will be mentioned. The first page of every chapter shall not carry the header.

I've been trying to do this but the only the title appears on all pages :?

Code: Select all

\documentclass[pdftex,12pt,a4paper]{report}
\usepackage{url}
\usepackage{subfigure}

\usepackage[top=1.5in, bottom=1in, left=1.5in, right=1in]{geometry}
\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}
\usepackage[pdftex]{graphicx}
\usepackage{fancyhdr}
\fancyhead{}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{
\markboth{\chaptername\
\thechapter.\ #1}{}}



%\fancyhead[LE]{Introduction}    
\fancyhead[LO]{Smartphone Based ECG Analysis System}






Last edited by komal on Wed Jun 08, 2011 8:32 pm, edited 1 time 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

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

chapter name in header

Post by localghost »

Please get used to always building a minimal example that is compilable for everybody as provided. Otherwise it becomes difficult to give specific help. Especially when a problem is more complicated.

The code below merges the demands from another topic you initiated [1]. So it should cover all things that you requested. In case that you use another document class, please tell us. The same applies to modifications of the page styles.

Code: Select all

\documentclass[11pt,a4paper,english]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{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[\thepage][][\chaptertitle]{\Title}{}{\thepage}
	\headrule
}
\newpagestyle{main}{%
  \sethead[\thepage][][\thechapter\enspace\chaptertitle]{\Title}{}{\thepage}
	\headrule
}
\newpagestyle{back}{%
  \sethead[\thepage][][\chaptertitle]{\Title}{}{\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}
For details study the manuals of the involved packages, especially that of the titlesec package, which here is responsible for the different page styles. As always, the blindtext package is only for creating dummy text, thus not part of the solution.

[1] View topic: customized page numbers


Thorsten
komal
Posts: 14
Joined: Thu Jun 02, 2011 1:57 pm

Re: chapter name in header

Post by komal »

I have tried your code and it runs perfectly but I actually want it in the report form.
How can I achieve the same header format with the following document class:
\documentclass[11pt,a4paper]{report}
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

chapter name in header

Post by localghost »

Add another entry to the option list for the document class.

Code: Select all

\documentclass[11pt,a4paper,openany]{book}
This mimics the default behaviour of the »report« class.

The »report« class doesn't define the commands \frontmatter, \mainmatter and \backmatter. You would need to do this subsequently for a document with the »report« class. With the additional option as shown above the »book« class almost behaves like the »report« class. For a single-sided document add oneside to the option list.
komal
Posts: 14
Joined: Thu Jun 02, 2011 1:57 pm

chapter name in header

Post by komal »

I've changed the option but it only prints the title in Header, the chapter name does not appear.




Code: Select all

\documentclass[11pt,a4paper,oneside,openany,english]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{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[\thepage][][\chaptertitle]{\Title}{}{\thepage}
   \headrule
}
\newpagestyle{main}{%
  \sethead[\thepage][][\thechapter\enspace\chaptertitle]{\Title}{}{\thepage}
   \headrule
}
\newpagestyle{back}{%
  \sethead[\thepage][][\chaptertitle]{\Title}{}{\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}
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

chapter name in header

Post by localghost »

Your demands say that you have to set up a document with double-sided page layout. Otherwise there would be no odd or even pages (it's not about the numbering). Or did I misunderstand something? So, remove the onesided option again (a silly suggestion of me).
komal
Posts: 14
Joined: Thu Jun 02, 2011 1:57 pm

Re: chapter name in header

Post by komal »

Actually when I get the print of this document, the pages will not be in a book format. I would be using only one side of the paper for printing so I want my
Left margin = 1.5". This criteria does not hold for the book format.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

chapter name in header

Post by localghost »

komal wrote:[…] I would be using only one side of the paper for printing so I want my Left margin = 1.5". This criteria does not hold for the book format.
And how does the rest of the margins look like? And what is your paper format? A little bit more precision in your descriptions would be helpful. Take a look at the geometry package, which I already included in my sample code (but without options). It lets you specify a lot of parameters concerning page and paper dimensions.
komal
Posts: 14
Joined: Thu Jun 02, 2011 1:57 pm

Re: chapter name in header

Post by komal »

top=1.5in, bottom=1in, left=1.5in, right=1in

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.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

chapter name in header

Post by Stefan Kottwitz »

Hi Komal,
komal wrote:Error: Option clash for package geometry.
it seems you're loading the geometry twice. Just check that and load it only once, with the desired settings. Options for geometry could also be set after loading by the command \geometry:

Code: Select all

\geometry{top=1.5in, bottom=1in, left=1.5in, right=1in}
Stefan
LaTeX.org admin
Post Reply