Page Layout ⇒ fancyhdr | Book Title in even Headers, Part Name on odd
fancyhdr | Book Title in even Headers, Part Name on odd
Hi,
I would to get the title name (book) at even headers (left), and part name at odd headers (right).
I try to get it using the fancyhdr package; There's no problem for chapters or sections, but I'm unable to put the part name at right page headers.
I'm using a book class.
How can i solve it?
Thank you for your time,
Steve,
I would to get the title name (book) at even headers (left), and part name at odd headers (right).
I try to get it using the fancyhdr package; There's no problem for chapters or sections, but I'm unable to put the part name at right page headers.
I'm using a book class.
How can i solve it?
Thank you for your time,
Steve,
Last edited by Stevenet on Mon Nov 07, 2011 4:08 pm, edited 1 time in total.
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and many kinds of documents
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
fancyhdr | Book Title in even Headers, Part Name on odd
It could be done by a supplement to some helper macros for the \part command.
This way you get a command \parttitle which you can use wherever needed.
Best regards and welcome to the board
Thorsten
Code: Select all
\documentclass[11pt]{book}
\usepackage[T1]{fontenc}
\makeatletter
\def\@part[#1]#2{%
\gdef\parttitle{#1}
\ifnum \c@secnumdepth >-2\relax
\refstepcounter{part}%
\addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
\else
\addcontentsline{toc}{part}{#1}%
\fi
\markboth{}{}%
{\centering
\interlinepenalty \@M
\normalfont
\ifnum \c@secnumdepth >-2\relax
\huge\bfseries \partname\nobreakspace\thepart
\par
\vskip 20\p@
\fi
\Huge \bfseries #2\par}%
\@endpart
}
\def\@spart#1{%
\gdef\parttitle{#1}
{\centering
\interlinepenalty \@M
\normalfont
\Huge \bfseries #1\par}%
\@endpart
}
\makeatother
\begin{document}
\part{Bar}
\parttitle
\part[Foo]{Bar}
\parttitle
\end{document}
Best regards and welcome to the board
Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: fancyhdr | Book Title in even Headers, Part Name on odd
Well, i'm trying something like this;
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[RO,LE]{\small\thepage}
\fancyhead[LO]{\small 'the book title'}% odd page header and number to right top
\fancyhead[RE]{\small @part }%Even page header and number at left top
\fancyfoot[L,R,C]{}
But, only puts the odd pages. There's a way (on this way please) to get the part name at even headers?
thank you,
Steve,
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[RO,LE]{\small\thepage}
\fancyhead[LO]{\small 'the book title'}% odd page header and number to right top
\fancyhead[RE]{\small @part }%Even page header and number at left top
\fancyfoot[L,R,C]{}
But, only puts the odd pages. There's a way (on this way please) to get the part name at even headers?
thank you,
Steve,
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
fancyhdr | Book Title in even Headers, Part Name on odd
You only have to combine my proposal with your page layout.Stevenet wrote:[…] There's a way (on this way please) to get the part name at even headers? […]
Code: Select all
\documentclass[11pt]{book}
\usepackage[T1]{fontenc}
\usepackage{fancyhdr}
\title{The Book Title}
\author{The Author}
\makeatletter
\let\thetitle\@title % Document title saved in command
\let\theauthor\@author % Document author saved in command
\def\@part[#1]#2{%
\gdef\parttitle{#1}
\ifnum \c@secnumdepth >-2\relax
\refstepcounter{part}%
\addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
\else
\addcontentsline{toc}{part}{#1}%
\fi
\markboth{}{}%
{\centering
\interlinepenalty \@M
\normalfont
\ifnum \c@secnumdepth >-2\relax
\huge\bfseries \partname\nobreakspace\thepart
\par
\vskip 20\p@
\fi
\Huge \bfseries #2\par}%
\@endpart
}
\def\@spart#1{%
\gdef\parttitle{#1}
{\centering
\interlinepenalty \@M
\normalfont
\Huge \bfseries #1\par}%
\@endpart
}
\makeatother
\fancyhf{}
\fancyhead[RO,LE]{\small\thepage}
\fancyhead[LO]{\small\thetitle} % Odd page header and number to right top
\fancyhead[RE]{\small\parttitle} % Even page header and number at left top
\pagestyle{fancy}
\begin{document}
\part{Bar}
\parttitle
\part[Foo]{Bar}
\parttitle
\end{document}
And please use the »Code« button when posting code to tag it as such (as you can see it in my posts). It just keeps your posts clear and legible.
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: fancyhdr | Book Title in even Headers, Part Name on odd
You right! Thank you very much, your code fits perfectly what i need.
Next time i'll put the code, using the tag.
Thank you again!
Steve,
Next time i'll put the code, using the tag.
Thank you again!
Steve,
fancyhdr | Book Title in even Headers, Part Name on odd
Hi again,
Two questions more;
Steve,
Two questions more;
- On the same book, (using now the above fancyhdr headers) i need that "last pages"; this is the blank even pages before new chapter-starting odd pages, will show really empty, so if at this last-even pages, if there's no content, should miss the headers. I'm actually using an \input for each chapter, so every chapter is a file inserted. How can i improve this?
- I have some long chapter titles, that are 'newlined' with \\. Although, note that the spacing between lines, is too much for a title. How con 'compress' the spacing between lines on chapter titles?
Steve,
Last edited by Stevenet on Mon Nov 07, 2011 4:07 pm, edited 1 time in total.
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
fancyhdr | Book Title in even Headers, Part Name on odd
Section 15 of the fancyhdr manual suggests to redefine the \cleardoublepage command. A diverting to achieve what you want is introduced in the below code (for more clarity again the complete example as given earlier).Stevenet wrote:[…] On the same book, (using now the above fancyhdr headers) i need that "last pages"; this is the blank even pages before new chapter-starting odd pages, will show really empty, so if at this last-even pages, if there's no content, should miss the headers. I'm actually using an \input for each chapter, so every chapter is a file inserted. How can i improve this? […]
Why do you force line breaks in chapter headings? The automatic line break should work well.Stevenet wrote:[…] I have some long chapter titles, that are 'newlined' with \\. Although, note that the spacing between lines, is too much for a title. How con 'compress' the spacing between lines on chapter titles? […]
Code: Select all
\documentclass[11pt]{book}
\usepackage[T1]{fontenc}
\usepackage{fancyhdr}
\title{The Book Title}
\author{The Author}
\makeatletter
\let\thetitle\@title % Document title saved in command
\let\theauthor\@author % Document author saved in command
\def\@part[#1]#2{%
\gdef\parttitle{#1}
\ifnum \c@secnumdepth >-2\relax
\refstepcounter{part}%
\addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
\else
\addcontentsline{toc}{part}{#1}%
\fi
\markboth{}{}%
{\centering
\interlinepenalty \@M
\normalfont
\ifnum \c@secnumdepth >-2\relax
\huge\bfseries \partname\nobreakspace\thepart
\par
\vskip 20\p@
\fi
\Huge \bfseries #2\par}%
\@endpart
}
\def\@spart#1{%
\gdef\parttitle{#1}
{\centering
\interlinepenalty \@M
\normalfont
\Huge \bfseries #1\par}%
\@endpart
}
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
\hbox{}
\thispagestyle{empty}
\newpage
\if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother
\fancyhf{}
\fancyhead[RO,LE]{\small\thepage}
\fancyhead[LO]{\small\thetitle} % Odd page header and number to right top
\fancyhead[RE]{\small\parttitle} % Even page header and number at left top
\pagestyle{fancy}
\begin{document}
\part{Foo}
\chapter{Foo}
\chapter{Bar}
\end{document}
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: fancyhdr | Book Title in even Headers, Part Name on odd
Thanks again. The question of blank pages is perfectly solved!
The question of titles spacing; Well, sometimes in order to better explain the chapter's content, could be better to force line breaks in titles (ie when a phrase starts with something like 'Research investment: \\ The regional potential'). But when i do that... i get an over spacing between lines...
thank you for your time,
Steve,
The question of titles spacing; Well, sometimes in order to better explain the chapter's content, could be better to force line breaks in titles (ie when a phrase starts with something like 'Research investment: \\ The regional potential'). But when i do that... i get an over spacing between lines...
thank you for your time,
Steve,
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
fancyhdr | Book Title in even Headers, Part Name on odd
The \\ command for manual line breaks accepts an optional argument where you can insert valid length values. You could try something like this.
The final adjustment is up to you. Remember that this line break will also occur in the ToC entry for the concerned chapter. So you might want to have a manual line break for the actual heading and an untouched ToC entry.
The optional argument also goes into the headers and so does not cause them to be messed up.
Code: Select all
\chapter{Research investment: \\[-0.5ex] The regional potential}
Code: Select all
\chapter[Research investment: The regional potential]{Research investment: \\[-0.5ex] The regional potential}
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: fancyhdr | Book Title in even Headers, Part Name on odd
Again, thanks a lot. Now titles spacing are more compressed and looks optimal for our book.
best regards,
Steve,
best regards,
Steve,