0

I used nomencl and created a page of nomenclatures in my paper, I want to put this page and this page only into a box, while everything else are to remain the same.

I tried the following code I found online but it puts a watermark of "draft" on the first page (before my nomenclature page) and boxed every page after that.

\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}}

Does anyone have a better solution? Thank you!

keroro
  • 33

1 Answers1

0

\AddToHook{shipout/background}

We can draw the frame using tikz and add to background using \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}

Using the background package

\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}

The reason you get the watermark "draft" on your first page is because the backgound package set background for every page by default. And you put the \SetBgContents{} command locally in your document. So the pages before \SetBgContents{} have been defined will use the default background figure which is big red color slanted text "draft" in the center of the page. You need explicit set \NoBgThispage in order to make a particular page without background. That is why I add \AddToHook{shipout/before}{\NoBgThispage} to set the rest of the pages without the box frame.

Tom
  • 7,318
  • 4
  • 21