![如何在书中制作精美的彩色背景页眉和页脚?](https://linux22.com/image/416283/%E5%A6%82%E4%BD%95%E5%9C%A8%E4%B9%A6%E4%B8%AD%E5%88%B6%E4%BD%9C%E7%B2%BE%E7%BE%8E%E7%9A%84%E5%BD%A9%E8%89%B2%E8%83%8C%E6%99%AF%E9%A1%B5%E7%9C%89%E5%92%8C%E9%A1%B5%E8%84%9A%EF%BC%9F.png)
我希望获得以下标题:
梅威瑟:
\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}