What I'm trying to do
I am creating some handwriting drill sheets. In these sheets, the exact same pattern is repeated horizontally and vertically over the entire page. The following 3 images were created using Inkscape, each of them represent the content of a single page that I want to create using TikZ.
What I know
I just learned that I can define a pattern inside \newsavebox
.
\documentclass{article}
\usepackage{tikz}
\newsavebox \mybox
\sbox \mybox {%
\tikz{%
\draw (0,0) circle (0.2);
\draw (0,0) circle (0.4);
\draw (0,0) circle (0.6);
\draw (0,0) circle (0.8);
\draw (0,0) circle (1);
}%
}
\begin{document}
\begin{tikzpicture}
\node at (0, 0) {\usebox\mybox};
\node at (2, 0) {\usebox\mybox};
\end{tikzpicture}
\end{document}
I also know that I can use loops to repeat the same pattern so that it fills the entire page (without exceeding the page borders).
\documentclass{article}
\usepackage{parskip}
\usepackage[showframe]{geometry}
\usepackage{tikz}
\newsavebox \mybox
\sbox \mybox {%
\tikz{%
\draw (0,0) circle (0.2);
\draw (0,0) circle (0.4);
\draw (0,0) circle (0.6);
\draw (0,0) circle (0.8);
\draw (0,0) circle (1);
}%
}
\begin{document}
\begin{tikzpicture}
\foreach \row in {2,4,...,18} {
\foreach \column in {2,4,...,14} {
\node at (\column, \row) {\usebox\mybox};
}
}
\end{tikzpicture}
\end{document}
Sometimes the page dimension is changed using the geometry
package. When that hapens, I need to manually update the number of iterations of the loop and see if the number of repetitions don't exceed the page border. I wish the loop automatically stopped when it reaches the right limit of the page or the bottom limit of the page.
I also know how to repeat something until the right limit of the page is reached by using \xleaders
. (see this answer). I used that knowledge to repeat the tikz graphic (see minimal working example below). However, the problem is that multiple tikzpicture
environment are used. I wished a single tikzpicture
is used in order to reduce the complexity of the source code.
\documentclass{article}
\usepackage{parskip}
\usepackage[showframe]{geometry}
\usepackage{tikz}
\newsavebox \mybox
\sbox \mybox {%
\tikz{%
\draw (0,0) circle (0.2);
\draw (0,0) circle (0.4);
\draw (0,0) circle (0.6);
\draw (0,0) circle (0.8);
\draw (0,0) circle (1);
}%
}
\newcommand\asteriskfill{\leavevmode\xleaders\hbox{%
\begin{tikzpicture}
\node at (0, 0) {\usebox\mybox};
\end{tikzpicture}%
}%
\hfill\kern0pt}
\begin{document}
\asteriskfill
\end{document}
I don't know how to repeat a pattern until the bottom limit of the page is reached.
The question
How to repeat the exact same TikZ pattern to use the entire available space in the page without exceeding page limits?
I thought that a possible way to tackle this problem would be to define a pattern using \newsavebox
and somehow define a macro that repeats the same box horizontally and vertically until the page limits are reached.
\newsavebox
and find a way to repeat that pattern horizontally and vertically as much as possible. This way, I don't need to infer the pattern size.