如何使装饰边框更靠近纸张边缘?

如何使装饰边框更靠近纸张边缘?

谢谢这个答案, (到我自己的问题)我找到了一种使用图像为文本创建装饰边框的方法。我现在的问题是我想让装饰边框离文本更远,也就是说,更靠近纸张的边缘。(任何方法都可以。)

这是我的代码:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%  Compile with --shell-escape flag!  %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\documentclass[11pt]{article}

\usepackage{lipsum} % just for the dummy text
\usepackage{tikzpagenodes}

\AddToHook{shipout/background}{
% ORIGINAL %  \begin{tikzpicture}[remember picture, overlay,inner sep=0pt,outer sep=0pt]
  \begin{tikzpicture}[remember picture, overlay,inner sep=40pt,outer sep=0pt]
  \node[anchor=south,text width=\textwidth] at (current page text area.north) {
    \foreach \x in {0,...,6}{\includegraphics[width=0.14285\textwidth,height=1.5cm]{resources/5rFkP.pdf}}% 1/7=0.14285
  };
  \node[anchor=north,text width=\textwidth] at (current page text area.south) {
    \foreach \x in {0,...,6}{\includegraphics[width=0.14285\textwidth,height=1.5cm]{resources/5rFkP.pdf}}% 1/7=0.14285
  };  
  \node[anchor=south,rotate=90,text width=\textheight] at (current page text area.west) {
    \foreach \x in {0,...,11}{\includegraphics[width=0.0833\textheight,height=1.5cm]{resources/5rFkP.pdf}}% 1/12=0.0833
  };
  \node[anchor=south,rotate=-90,text width=\textheight] at (current page text area.east) {
    \foreach \x in {0,...,11}{\includegraphics[width=0.0833\textheight,height=1.5cm]{resources/5rFkP.pdf}}% 1/12=0.0833
  };       

  \node[anchor=north west] at (current page text area.south east) {\includegraphics[width=1.5cm,height=1.5cm]{resources/5rFkP.pdf}};
  \node[anchor=north east] at (current page text area.south west) {\includegraphics[width=1.5cm,height=1.5cm]{resources/5rFkP.pdf}};
  \node[anchor=south west] at (current page text area.north east) {\includegraphics[width=1.5cm,height=1.5cm]{resources/5rFkP.pdf}};
  \node[anchor=south east] at (current page text area.north west) {\includegraphics[width=1.5cm,height=1.5cm]{resources/5rFkP.pdf}};    
  
    
  \end{tikzpicture}
}

\begin{document}

\lipsum

\end{document}

您可以看到我在图案和文本之间添加了一些空间。显然,这会导致装饰边框的边和角之间也出现一些间距:

图案边和角之间的间距

这项工作仍在进行中,但考虑到我最终将专门为角落制作一个独特的图像,因此使用相同的图像从一个角落到另一个角落绘制图案是这不是我的问题的解决方案

在侧面添加更多图案单元并不会导致填补我添加的额外间距所产生的空隙,因为侧面不是居中对齐,而是与文本对齐。

问题:

如何制作更靠近页面边缘的装饰边框,同时填补额外间距造成的空隙?(要查看原始内容,请取消注释标记的行% ORIGINAL %并注释掉紧随其后的行,或参阅这个答案观看图片。

复制的资源:

PDF格式的花卉图案单元:https://mega.nz/file/05ckAThb#HPAqp1XR2l_cTzzpKsYIA5V02L-VQ3p22Bq4Z8UqZOM

答案1

这是一个使用的解决方案chains

\documentclass{article}
\usepackage{lipsum}
\usepackage{tikz, tikzpagenodes}
\usetikzlibrary{chains}
\AddToHook{shipout/background}{
\begin{tikzpicture}[remember picture, overlay, start chain, inner sep=0, outer sep=0, node distance=0]
\newcommand{\w}{1.9cm}
\newcommand{\h}{1.5cm}
\newcommand{\n}{8}
\newcommand{\m}{12}
\newcommand{\corner}{\includegraphics[width=\h, height=\h]{example-image-duck}}
\newcommand{\topbottom}{\includegraphics[width=\w, height=\h]{example-grid-100x100pt}}
\newcommand{\leftrigth}{\includegraphics[width=\w, height=\h, angle=90]{example-grid-100x100pt}}
\node[on chain, anchor=south east] at ([xshift=(\textwidth-\n*\w)/2, yshift=(\m*\w-\textheight)/2] current page text area.north west) {\corner};
\foreach \x in {1,...,\n}
\node[on chain=going right]{\topbottom};
\node[on chain=going right]{\corner};
\foreach \x in {1,...,\m}
\node[on chain=going below]{\leftrigth};
\node[on chain=going below]{\corner};
\foreach \x in {1,...,\n}
\node[on chain=going left]{\topbottom};
\node[on chain=going left]{\corner};
\foreach \x in {1,...,\m}
\node[on chain=going above]{\leftrigth};
\end{tikzpicture}
}
\begin{document}
\lipsum[1-5]
\end{document}

带有图像边框的页面

答案2

这显示了如何在不使用 tikz 或 foreach 的情况下执行此操作。请注意在 中使用\dimen0而不是 1.5cm \numexpr。此外,还有\includegraphicsate\dimen0\dimen2

\documentclass[11pt]{article}

\usepackage{lipsum} % just for the dummy text
\usepackage{graphicx}

\AddToHook{shipout/background}{%
  \dimen0=1.5cm% desired width and height
  \dimen1=\dimexpr \paperwidth-2cm\relax
  \count1=\numexpr \dimen1/\dimen0\relax% x number
  \dimen3=\dimexpr \paperheight-2cm\relax
  \count2=\numexpr \dimen3/\dimen0\relax% y number
  \divide\dimen1 by \count1% width
  \divide\dimen3 by \count2% height
  \sbox0{\includegraphics[width=\dimen1,height=\dimen3]{images/5rFkP.pdf}}% convert
% at this point \wd0 and \ht0 are the width and height
  \dimen0=1cm% x
  \dimen1=\dimexpr -1cm-\ht0\relax% y
  \count3=\count1
  \loop\ifnum\count3>1
    \advance\count3 by -1
    \put (\dimen0,\dimen1) {\usebox0}%
    \advance\dimen0 by \wd0
  \repeat
  \count3=\count2
  \loop\ifnum\count3>1
    \advance\count3 by -1
    \put (\dimen0,\dimen1) {\usebox0}%
    \advance\dimen1 by -\ht0
  \repeat
  \count3=\count1
  \loop\ifnum\count3>1
    \advance\count3 by -1
    \put (\dimen0,\dimen1) {\usebox0}%
    \advance\dimen0 by -\wd0
  \repeat
  \count3=\count2
  \loop\ifnum\count3>1
    \advance\count3 by -1
    \put (\dimen0,\dimen1) {\usebox0}%
    \advance\dimen1 by \ht0
  \repeat
}

\begin{document}


\lipsum

\end{document}

此版本与原版一样跟随文本区域。我尝试旋转图像,但看起来很奇怪。

我在这里使用保存箱,因为它们很多并且\usebox比 更快\includegraphics

\documentclass[11pt]{article}

\usepackage{lipsum} % just for the dummy text
\usepackage{graphicx}

\AddToHook{shipout/background}{%
  \dimen0=1.5cm% desired width
  \count1=\numexpr \textwidth/\dimen0\relax% x number
  \sbox0{\includegraphics[width=\dimexpr \textwidth/\count1\relax ,height=1.5cm]{images/5rFkP.pdf}}
  \dimen0=\dimexpr 1in+\oddsidemargin\relax
  \count2=\count1
  \loop\ifnum\count2>0
    \advance\count2 by -1
    \put (\dimen0,-2.5cm) {\usebox0}%
    \put (\dimen0,{\dimexpr 1cm-\paperheight}) {\usebox0}%
    \advance\dimen0 by \wd0
  \repeat
  \dimen0=1.5cm% desired height
  \count1=\numexpr \textheight/\dimen0\relax% y number
  \sbox0{\includegraphics[width=1.5cm, height=\dimexpr \textheight/\count1\relax]{images/5rFkP.pdf}}
  \dimen0=-\dimexpr 1in+\topmargin+\headheight+\headsep+\ht0\relax
  \count2=\count1
  \loop\ifnum\count2>0
    \advance\count2 by -1
    \put (1cm, \dimen0) {\usebox0}%
    \put ({\dimexpr \paperwidth-2.5cm}, \dimen0) {\usebox0}%
    \advance\dimen0 by -\ht0
  \repeat
  \sbox0{\includegraphics[width=1.5cm, height=1.5cm]{images/5rFkP.pdf}}%
  \put (1cm, -2.5cm) {\usebox0}%
  \put (\dimexpr \paperwidth-2.5cm\relax, -2.5cm) {\usebox0}%
  \put (1cm, \dimexpr 1cm-\paperheight\relax) {\usebox0}%
  \put (\dimexpr \paperwidth-2.5cm\relax, \dimexpr 1cm-\paperheight\relax) {\usebox0}%
}

\begin{document}

\lipsum

\end{document} 

我想到将整个背景创建为单个(全局)保存箱会快得多。

\documentclass[11pt]{article}

\usepackage{lipsum} % just for the dummy text
\usepackage{graphicx}

\newsavebox{\background}

\savebox{\background}{\begin{minipage}[t][\paperheight][t]{\paperwidth}
  \baselineskip=0pt
  \lineskip=0pt
  \dimen0=1.5cm% desired width and height
  \dimen1=\dimexpr \paperwidth-2cm\relax
  \count1=\numexpr \dimen1/\dimen0\relax% x number
  \dimen3=\dimexpr \paperheight-2cm\relax
  \count2=\numexpr \dimen3/\dimen0\relax% y number
  \divide\dimen1 by \count1% width
  \divide\dimen3 by \count2% height
  \sbox0{\includegraphics[width=\dimen1,height=\dimen3]{images/5rFkP.pdf}}% convert image
  \sbox1{\loop\ifnum\count1>0
    \advance\count1 by -1
    \usebox0%
  \repeat}% create top and bottom
  \setbox2=\vbox{\hsize=\wd0
  \loop\ifnum\count2>2
    \advance\count2 by -1
    \usebox0\par
  \repeat}% create sides
  \leftskip=1cm% create background page
  \rightskip=1cm
  \hrule height0pt % put baseline at very top
  \vskip 1cm
  \usebox1\par
  \usebox2\hfill\usebox2\par
  \usebox1
  \end{minipage}}

\AddToHook{shipout/background}{\put(0pt,0pt) {\usebox\background}}

\begin{document}

\lipsum

\end{document}

相关内容