0

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[\bfseries\thepage][][\bfseries\thechapter.~\chaptertitle]{\bfseries\thechapter. ~\chaptertitle}{}{\bfseries\thepage}
    \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.

1 Answer 1

1

Try this:

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

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

\newpagestyle{mystyle}{%
    \headrule%
    \sethead[\includeHeaderImage\bfseries\thepage][][\bfseries\thechapter.~\chaptertitle]
      {\includeHeaderImage\bfseries\thechapter. ~\chaptertitle}
      {}{\bfseries\thepage}
    \setfoot[\includeFooterImage][][]{\includeFooterImage}{}{}
}
\pagestyle{mystyle}

\usepackage{tikz}

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

\newcommand\includeFooterImage{%
  \includeImageOnPage
    {\@footerimage}{width=\paperwidth, height=50pt}{south east}%
}

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

\newcommand\setHeaderImage[1]{\def\@headerimage{#1}}
\newcommand\setFooterImage[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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .