TransWikia.com

How to do fancy color background header and footer in a book?

TeX - LaTeX Asked on December 3, 2021

I would like to get header as :

enter image description here

enter image description here

MWE:

documentclass[11pt,a4paper,openright,fleqn,twoside]{book}

usepackage[paperwidth=16cm,paperheight=24cm]{geometry}

usepackage{titleps}
newpagestyle{mystyle}{%
    headrule%
    sethead[bfseriesthepage][][bfseriesthechapter.~chaptertitle]{bfseriesthechapter. ~chaptertitle}{}{bfseriesthepage}
    setfoot{}{}{}
}%

usepackage{lipsum}%

pagestyle{mystyle}
begin{document}
    
chapter{First Chapter}
lipsum[1-2]
    
section{First Section}
lipsum[3-4]
    
subsection{First Subsection}
lipsum[5-6]    
end{document}. 

This codes do not provide the required header. How can I do this?
Note: I want to give local image input to the image of the fish in the background of the header.

One Answer

Try this:

documentclass[11pt,a4paper,openright,fleqn,twoside]{book}

usepackage[paperwidth=16cm,paperheight=24cm]{geometry}
usepackage{titleps}
usepackage{lipsum}

newpagestyle{mystyle}{%
    headrule%
    sethead[includeHeaderImagebfseriesthepage][][bfseriesthechapter.~chaptertitle]
      {includeHeaderImagebfseriesthechapter. ~chaptertitle}
      {}{bfseriesthepage}
    setfoot[includeFooterImage][][]{includeFooterImage}{}{}
}
pagestyle{mystyle}

usepackage{tikz}

makeatletter
newcommandincludeHeaderImage{%
  includeImageOnPage
    {@headerimage}{width=paperwidth, height=50pt}{north east}%
}

newcommandincludeFooterImage{%
  includeImageOnPage
    {@footerimage}{width=paperwidth, height=50pt}{south east}%
}

% #1 = a cmd containing figure file, #2 = figure options, #3 = tikz node anchor
newcommandincludeImageOnPage[3]{%
  ifx#1@empty
  else
    edef@tempa{%
      noexpandtikz[overlay, remember picture]
        noexpandnode[inner sep=0pt, anchor=#3] at (current page.#3)
          {noexpandincludegraphics[#2]{#1}};%
    }
    @tempa
  fi
}

newcommandsetHeaderImage[1]{def@headerimage{#1}}
newcommandsetFooterImage[1]{def@footerimage{#1}}

% init
setHeaderImage{}
setFooterImage{}
makeatother
begin{document}
    
chapter{First Chapter}
lipsum[1]
newpage

% set new header and footer images
setHeaderImage{example-image-a}
setFooterImage{example-image-b}
section{First Section}
lipsum[3-4]
newpage

% cancel
setHeaderImage{}
setFooterImage{}
subsection{First Subsection}
lipsum[5-6]
end{document}

enter image description here

Answered by muzimuzhi Z on December 3, 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