我无法使该命令具有确定性。我在使用 PDFLaTeX 时遇到的奇怪行为在以下 MWE 的评论中进行了解释。我在原始文档中检查了与包的冲突afterpage
,也可能是通过包的冲突multicol
,并在阅读了文档中的警告后background
,但没有帮助。我该怎么办?
\documentclass[oneside,a4paper]{book}%
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage[pages=all]{background}
\backgroundsetup{opacity=0.7,contents={\Huge MY BACKGROUND}}
\begin{document}
\thispagestyle{plain}%
%
\BgThispage{}\BgThispage{}\BgThispage{} %Shorthand to enhance opacity just here.
TITLE-PAGE
\clearpage\thispagestyle{empty}
\NoBgThispage{}
\thispagestyle{empty}
A first BgLess page.
\clearpage\thispagestyle{empty}
%\NoBgThispage{} %THIS COMMAND WILL MAKE ALL THE FOLLOWING PAGES MISS THE BACKGROUND.
\textbf{No BG here, please, but yes afterwards. Shouldn't it be as easy as in the previous page?}
\clearpage\thispagestyle{empty}
%\BgThispage% Even this command will be bypassed.
\clearpage
%\NoBgThispage{} %Again, this will affect every remaining page.
TOC page.
\clearpage%
\lipsum[1-10]
\vfill{}Why is BG missing here?
\end{document}
答案1
在@Ulrike Fischer 的评论和这个答案之后:https://tex.stackexchange.com/a/210105/36389
一种可能的解决方法是考虑在之后更改背景设置,既可以增强特定页面的不透明度,也可以省略其他页面的背景\begin{document}
。在本例中,我定义了 3 个命令来保存文档中不同的常见设置:
\documentclass[oneside,a4paper]{book}%
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage[pages=all]{background}
\newcommand{\TitlePageBgOpacity}{0.95}
\newcommand{\NormalPageBgOpacity}{0.5}
\newcommand{\NoBgPageBgOpacity}{0}
\backgroundsetup{contents={\Huge MY BACKGROUND}}
\begin{document}
\thispagestyle{plain}%
%
\backgroundsetup{opacity=\TitlePageBgOpacity}
TITLE-PAGE
\clearpage\thispagestyle{empty}
\backgroundsetup{opacity=\NoBgPageBgOpacity}
\thispagestyle{empty}
A first BgLess page.
\clearpage\thispagestyle{empty}
%\backgroundsetup{opacity=\NoBgPageBgOpacity}
\textbf{No BG here, please, but yes afterwards. Shouldn't it be as easy as in the previous page?}
\clearpage\thispagestyle{empty}
\backgroundsetup{opacity=\NormalPageBgOpacity}
\clearpage
\backgroundsetup{opacity=\NoBgPageBgOpacity}
TOC page.
\clearpage%
\backgroundsetup{opacity=\NormalPageBgOpacity}
\lipsum[1-10]
\vfill{}Why is BG missing here?
\end{document}