![使用 ltshipout,如何使某些“图片”环境的内容在页面是彩色的情况下以及仅在第一页上可见?](https://linux22.com/image/433881/%E4%BD%BF%E7%94%A8%20ltshipout%EF%BC%8C%E5%A6%82%E4%BD%95%E4%BD%BF%E6%9F%90%E4%BA%9B%E2%80%9C%E5%9B%BE%E7%89%87%E2%80%9D%E7%8E%AF%E5%A2%83%E7%9A%84%E5%86%85%E5%AE%B9%E5%9C%A8%E9%A1%B5%E9%9D%A2%E6%98%AF%E5%BD%A9%E8%89%B2%E7%9A%84%E6%83%85%E5%86%B5%E4%B8%8B%E4%BB%A5%E5%8F%8A%E4%BB%85%E5%9C%A8%E7%AC%AC%E4%B8%80%E9%A1%B5%E4%B8%8A%E5%8F%AF%E8%A7%81%EF%BC%9F.png)
以下 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}