2

Thanks to this answer, (to my own question) I've found a way to create a decorative border for my text using images. My problem now is that I want to make the decorative border farther from the text, that is, closer to the edge of the paper. (Any way will do.)

Here is my code:

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

You can see that I've added some space between the pattern and the text. Obviously, this results in the some spacing also appearing between the sides and corners of the decorative border:

spacing between sides and corners of pattern

This is still a work in progress, but take into account that I will eventually make a unique image for the corners exclusively, so drawing the pattern from one corner to the other using the same image is not a solution to my problem.

Adding more pattern units to the sides does not result in filling the gaps created by the additional spacing I added, because the sides are not centre-aligned, but rather aligned with the text.

The Question:

How do I make a decorative border that is closer to the edge of the page while filling those gaps that are created by the extra spacing? (To see what the original looked like, uncomment the line labelled % ORIGINAL % and comment out the line that comes directly after it, or see this answer for an image.)

Resources for replication:

Flower pattern unit in PDF format: https://mega.nz/file/05ckAThb#HPAqp1XR2l_cTzzpKsYIA5V02L-VQ3p22Bq4Z8UqZOM

1

2 Answers 2

3

Here is a solution using 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}

A page with a border of images

3

This shows how to do it without using tikz or foreach. Note the use of \dimen0 instead of 1.5cm in \numexpr. Also, \includegraphics ate \dimen0 and \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}

This version follows the text area like the original. I tried rotating the image, but it looked odd.

I use saveboxes here because there are lots of them and \usebox is faster than \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} 

It occurred to me that it would be much faster to create the entire background as a single (global) savebox.

\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}
6
  • I learned a lot from your answer, thank you! You had me do quite some research to figure out what all the commands did, but now I can understand your code fairly better. As I've mentioned in my question, is there possibility to include different images in the corners? For demonstration purposes, you could just use \put(dimen0,dimen1) {\includegraphics[width=\dimen1,height=\dimen3]{CORNER-IMAGE.pdf}, for example. Also, would this work with non-square images (e.g. long rectangles)?
    – GPWR
    Commented Jan 5, 2023 at 3:03
  • And, last thing: What would be the best way to also include a bit of space between the decorative border and the page edge, for printing purposes? For instance, I can see that it touches the edge, naturally, but that would make it impossible to print for most conventional home printers (such as mine). Thank you so much again. I really appreciate your time, and clarity in your comments within your code! God bless.
    – GPWR
    Commented Jan 5, 2023 at 3:05
  • +1 @GPWR: When receiving an answer, you should upvote to show appreciation Commented Jan 5, 2023 at 8:09
  • 1
    You don't always need to use \dimen registers. In the case of \includegraphics, I did it mostly to make the code more readable. Adding a gap next to the edge is easy enough, but you never specified a size. Commented Jan 5, 2023 at 17:13
  • @hpekristiansen I totally agree. Thanks for the reminder. +1 ;)
    – GPWR
    Commented Jan 5, 2023 at 22:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .