以下 MCE 表明,如果页面是彩色的,则picture
环境的内容为:
- 在所有页面上
\AddToHook{shipout/background}
都可见,\AddToHook{shipout/foreground}
- 不可见
\AddToHook{shipout/firstpage}
。
picture
如果页面是彩色的并且仅在第一页,是否可以使某些环境的内容可见?
如图所示,或多或少能够做到这eso-pic
一点\AddToShipoutPictureBG*
(尽管当前页面可能不是第一个页面),但我不想依赖它并模仿它的行为。
\documentclass{article}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{eso-pic}
\newcommand{\test}[1]{\Huge\bfseries\color{blue}#1}
\pagecolor{yellow}
\AddToHook{shipout/background}{%
\begin{picture}(0,0)
\put(\textwidth,-.5\textheight){%
\test{background}%
}
\end{picture}
}
\AddToHook{shipout/foreground}{%
\begin{picture}(0,0)
\put(0,-.5\textheight){%
\test{foreground}%
}
\end{picture}
}
\AddToHook{shipout/firstpage}{%
\begin{picture}(0,0)
\put(.5\textwidth,-.5\textheight){%
\test{firstpage}%
}
\end{picture}
}
\AddToShipoutPictureBG*{%
\AtTextCenter{%
\test{eso-pic}
}%
}
\begin{document}
\lipsum[1-10]
\end{document}
答案1
shipout/firstpage
是错误的钩子。它确实在最开始,正如文档所说
它应该只包含指导后处理器处理 .dvi 或 .pdf 输出所需的 \special 或类似命令。
但您只能\AddToHookNext
在下一页上获取一些内容:
\documentclass{article}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{eso-pic}
\newcommand{\test}[1]{\Huge\bfseries\color{blue}#1}
\pagecolor{yellow}
\AddToHookNext{shipout/background}{%
\put(\textwidth,-.5\textheight){%
\test{background}%
}
}
\AddToHookNext{shipout/foreground}{%
\put(0,-.5\textheight){%
\test{foreground}%
}
}
\AddToHook{shipout/firstpage}{%
\put(.5\textwidth,-.5\textheight){%
\test{firstpage}%
}
}
\AddToShipoutPictureBG*{%
\AtTextCenter{%
\test{eso-pic}
}%
}
\begin{document}
\lipsum[1-10]
\end{document}