TransWikia.com

Footer ruler on first page in fancyhdr with `book` but not in `part` part

TeX - LaTeX Asked on March 13, 2021

In the question Footer ruler on first page in fancyhdr with `book` I asked about the possibility to get a footer ruler on the first page of a chapter. The answer https://tex.stackexchange.com/a/566047/44119 gave the required result for this problem.

I now have a similar problem, where I want to have the footer ruler and footer text on the first page of a chapter but when I have a part I don’t want to have the footer ruler and footer text on that page.

The suggestion by @Bernard in comment on https://tex.stackexchange.com/a/566047/44119 was to use thispagestyle{empty} but thiis didn’t work, so I thought using of a newenvironment for this but this didn’t work either (my try is commented out at the moment.
My MWE:

documentclass[twoside]{book}
usepackage{lipsum}
usepackage{fancyhdr}
pagestyle{fancyplain}
renewcommand{footrulewidth}{0.4pt}
%
fancypagestyle{fancyplain}{
fancyhf{}
fancyhead[LE, RO]{bfseriesthepage}
fancyhead[LO]{bfseriesrightmark}
fancyhead[RE]{bfseriesleftmark}
fancyfoot[LE, RO]{bfseriesthepage}
fancyfoot[LO, RE]{bfseriesscriptsize Generated}
}
%
fancypagestyle{plain}{
fancyhf{}
fancyfoot[LE, RO]{textbf{thepage}}
fancyfoot[LO, RE]{bfseriesscriptsize Generated}
renewcommand{headrulewidth}{0pt}}

pagestyle{fancyplain}

newenvironment{MyPart}{
  fancyfoot[LO, RE]{}
  renewcommand{footrulewidth}{0.0pt}
}{
  fancyfoot[LO, RE]{bfseriesscriptsize Generated }
}

begin{document}

%% test based on suggestion by @Bernard in comment on https://tex.stackexchange.com/a/566047/44119:
part{Manual}
thispagestyle{empty}

%% my own idea:
begin{MyPart}
part{Manual}
end{MyPart}

chapter{My Chapter}
lipsum[1]
newpage
lipsum[1]
newpage
lipsum[1]

end{document}

2 Answers

The trouble is that also part uses the plain page style, which you have redefined to suit your needs. Worse, part does issue a newpage in order to force an empty verso page; your manual thispagestyle{empty} comes thus too late.

I think the only way here is to patch the definition of part. Either copy/paste the original definition from book.cls in your preamble with the suitabile substitution

renewcommandpart{%    <-- use renewcommand here
  if@openright
    cleardoublepage
  else
    clearpage
  fi
  thispagestyle{empty}%   <-- empty instead of plain
  if@twocolumn
    onecolumn
    @tempswatrue
  else
    @tempswafalse
  fi
  nullvfil
  secdef@part@spart}

or you let e.g. xpatch do the work for you

usepackage{xpatch}
xpatchcmd{part}{plain}{empty}{}{}

A MWE based on your code with the second solution is

documentclass[twoside]{book}

usepackage{lipsum}
usepackage{fancyhdr}

renewcommand{footrulewidth}{0.4pt}

fancypagestyle{fancyplain}{
fancyhf{}
fancyhead[LE, RO]{bfseriesthepage}
fancyhead[LO]{bfseriesrightmark}
fancyhead[RE]{bfseriesleftmark}
fancyfoot[LE, RO]{bfseriesthepage}
fancyfoot[LO, RE]{bfseriesscriptsize Generated}
}

fancypagestyle{plain}{
fancyhf{}
fancyfoot[LE, RO]{textbf{thepage}}
fancyfoot[LO, RE]{bfseriesscriptsize Generated}
renewcommand{headrulewidth}{0pt}}

pagestyle{fancyplain}

usepackage{xpatch}
xpatchcmd{part}{plain}{empty}{}{}

begin{document}

part{Manual}

chapter{My Chapter}
lipsum[1]
newpage
lipsum[1]
newpage
lipsum[1]

end{document}

enter image description here

Correct answer by campa on March 13, 2021

Using xpatch differently:

usepackage{ xpatch} 
makeatletter
xpatchcmd{@part}{#2}{#2thispagestyle{empty}}{}{}
makeatother

enter image description here

Answered by Bernard on March 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP