本质上,我有一个多章节文档,每个章节都应该有自己的整页背景。我修改了解决方案这里工作。问题是,我一直在使用,scrbook
而解决方案使用book
,当您更改类时它将不起作用。我怎样才能让这个解决方案在 scrbook 上工作?
原始代码:
\documentclass{book}
\usepackage{graphicx,eso-pic,lipsum,etoolbox}
\providecommand{\chapterhook}{}
\patchcmd{\chapter}{\thispagestyle}{\chapterhook\thispagestyle}{}{}
\newcommand{\chapterimage}[2][]{% \parthook[<options>]{<image>}
\renewcommand{\chapterhook}{% Update \parthook
\AddToShipoutPictureBG*{% Add picture to background of THIS page only
\AtPageLowerLeft{\includegraphics[width=\paperwidth,height=\paperheight,#1]{#2}}}% Insert image
\renewcommand{\chapterhook}{}}}% Restore \parthook
\graphicspath{{Pictures/}}
\begin{document}
\chapterimage{example-image-a}
\chapter*{First part}
\lipsum[1-2]
\end{document}
答案1
你只需要找到一个合适的命令来修补。例如,
\documentclass{scrbook}
\usepackage{graphicx,eso-pic,lipsum,etoolbox}
\providecommand{\chapterhook}{}
\makeatletter
\patchcmd{\scr@startchapter}{\thispagestyle}{\chapterhook\thispagestyle}{\typeout{Patching chapter worked OK!}}{\typeout{Patching chapter failed! Oh no!!}}
\newcommand*{\chapterimage}[2][]{% \parthook[<options>]{<image>}
\renewcommand{\chapterhook}{% Update \parthook
\AddToShipoutPictureBG*{% Add picture to background of THIS page only
\AtPageLowerLeft{%
\includegraphics[width=\paperwidth,height=\paperheight,#1]{#2}%
}%
}% Insert image
\renewcommand{\chapterhook}{}% Restore \parthook
}%
}
\makeatother
\begin{document}
some text
\chapterimage{example-image-a}
\chapter*{First part}
\lipsum[1-5]
\chapterimage{example-image-b}
\chapter{Second part}
\lipsum[1-5]
\end{document}