如何在书中制作精美的彩色背景页眉和页脚?

如何在书中制作精美的彩色背景页眉和页脚?

我希望获得以下标题:

在此处输入图片描述

在此处输入图片描述

梅威瑟:

\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}. 

此代码未提供所需的标头。我该怎么办?
笔记:我想将本地图像输入到标题背景中的鱼的图像中。

答案1

尝试这个:

\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}

在此处输入图片描述

相关内容