\AddToHook{shipout/background}

\AddToHook{shipout/background}

我在我的论文中使用nomencl并创建了一页术语,我想把这一页和只有这一页放进一个框里,而其他一切都保持不变。

我尝试了以下我在网上找到的代码,但它在第一页(我的命名法页面之前)放置了“草稿”水印,并在之后的每一页上加了框。

\usepackage{background}
\usetikzlibrary{calc}

\SetBgScale{1}
\SetBgAngle{0}
\SetBgColor{black}
\SetBgContents{
\begin{tikzpicture}[overlay,remember picture]
    \draw [line width=1pt,rounded corners=4pt,]
        ($ (current page.north west) + (2cm,-2cm) $)
        rectangle
        ($ (current page.south east) + (-2cm,2cm) $);
\end{tikzpicture}}

有谁有更好的解决方案吗?谢谢!

答案1

\AddToHook{shipout/background}

我们可以使用 tikz 绘制框架并使用以下方式添加到背景\AddToHook{shipout/background}{...some code...}

\documentclass{article}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{nomencl} 
\makenomenclature

\begin{document}
\AddToHook{shipout/background}{
\begin{tikz}[remember picture, overlay,shift=(current page.north west)]
\draw[rounded corners=4pt, line width = 1pt, black] (2cm,-2cm) -- (2cm,2cm-\paperheight) -- (\paperwidth-2cm, 2cm-\paperheight) -- (\paperwidth-2cm,-2cm)--cycle;
\end{tikz}
}
\printnomenclature
\clearpage

\RemoveFromHook{shipout/background}
\lipsum[1]
\nomenclature[a]{$E$}{Energy}
\nomenclature[a]{$m$}{Mass}
\nomenclature[a]{$c$}{Speed of Light}
\[E=m\cdot c^2 \]

\lipsum[2]
\end{document}

使用background

\documentclass{article}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{nomencl}
\usepackage{background}
\SetBgScale{1}
\SetBgAngle{0}
\SetBgColor{black}
\SetBgContents{
\begin{tikzpicture}[overlay,remember picture]
    \draw [line width=1pt,rounded corners=4pt,]
        ($ (current page.north west) + (2cm,-2cm) $)
        rectangle
        ($ (current page.south east) + (-2cm,2cm) $);
\end{tikzpicture}}
\makenomenclature

\begin{document}
\printnomenclature
\clearpage

\AddToHook{shipout/before}{
\NoBgThispage
}

\lipsum[1]
\nomenclature[a]{$E$}{Energy}
\nomenclature[a]{$m$}{Mass}
\nomenclature[a]{$c$}{Speed of Light}

\[E=m\cdot c^2 \]

\lipsum[2]
\end{document}

您在第一页上看到水印“草稿”的原因是软件包backgound默认为每一页设置了背景。并且您将命令\SetBgContents{}本地放在文档中。因此,在 \SetBgContents{} 之前定义的页面将使用默认背景图,即页面中心的大红色倾斜文本“草稿”。您需要明确设置\NoBgThispage才能使特定页面没有背景。这就是我添加\AddToHook{shipout/before}{\NoBgThispage}设置其余页面而不使用框的原因。

相关内容