使用 AtBeginShipout 调用的 tikzpicture 时是否有额外的页面?

使用 AtBeginShipout 调用的 tikzpicture 时是否有额外的页面?

我一直在尝试使用\AtBeginShipouttikz绘制页眉和页脚艺术,如创建新闻稿艺术的解决方案按用户贡萨洛·梅迪纳

遇到的一个问题是,文档末尾总是会出现一个仅包含艺术作品的额外页面。在下面的示例中,我预期输出两页,但实际输出了三页。这是为什么?防止这种情况发生的最佳方法是什么?

\AtBeginShipout使用with 的示例\tikzpicture会产生一个额外的页面:

\documentclass{article}

\usepackage{tikz}
\usepackage{atbegshi}
\usepackage{lipsum}

\newcommand\DrawSquare{
\begin{tikzpicture}[overlay]
\draw[fill=pink]
    (0,0) rectangle (10,-10);
\end{tikzpicture}
}

\AtBeginShipout{\DrawSquare}

\begin{document}
\lipsum[1-9]
\end{document}

输出缩略图:

输出

答案1

当你使用

\AtBeginShipout{<stuff>}

<stuff>插入到输入流中。但是,此时整个“当前页面”已经构建完毕并包含在框内\AtBeginShipoutBox。如果保留所有内容,则“当前页面”将被发送出去,然后<stuff>进行处理。

在您的实例中,一个overlay框被添加到输入流中,但并不构成要发送出的“当前页面”的一部分。

为了添加要发送的“当前页面”,您需要使用组合

\AtBeginShipout{\AtBeginShipoutAddToBox{<stuff>}}

或者

\AtBeginShipout{\AtBeginShipoutUpperLeft{<stuff>}}

答案2

更换:

\AtBeginShipout{\DrawSquare}

和:

\AtBeginShipout{\AtBeginShipoutAddToBox{\DrawSquare}}

解决了问题。输出由两页文本组成,两页都包含一个粉色方块。但是,我无法解释为什么会出现这个问题,也无法解释为什么这个解决方案有效。

找到了这个解决方案这里

相关内容