The TikZ manual explains about patterns:
There are a number of pitfalls and restrictions when using patterns. […]
[T]he phase of patterns is not well-defined, that is, it is not clear where the origin of the “first” tile is. To be more precise, PostScript and PDF on the one hand and SVG on the other hand define the origin differently. PostScript and PDF define a fixed origin that is independent of where the path lies. This has the highly desirable effect that if you use the same pattern to fill multiple paths, the outcome is the same as if you had filled a single path consisting of the union of all these paths.
In your case, this is not highly desirable.
If we knew where the actual origin is we could calculate the needed shifting but I believe it to be easier to draw with the main TikZ methodes not as a pattern (i.e. something that is handled by the “underlying grapih languages”) even though it might be slower.
In the following code, the dots are drawn with a special dash pattern
that has on segment of zero length but a round line cap. Thus, these dots are not drawn as a circle
(shape or path operation) but part of a line. Their size are controlled by the line width.
Rules:
The only flexible distances are
- the margin between the dotted columns,
- the width of the dotted columns and
- the vertical margin between the dots and the top and bottom of the column.
Variables:
columns
: number of dotted columns
dot distance
: distance between the dots' centers
dot diameter
: the diameter of the dots (not the radius)
margin
: the space between the outer dots' centers and the rectangles.
For the horizontal dimension this is a fixed length, for the vertical dimension it is considered to be a minimum.
minimal column sep
: the minimal horizontal space between the columns
Styles:
@dots
: internal style that sets the appropriate grid and line settings
rectangle
: the style of the rectangle
dots
: the style of the dots
diagram
: somewhat internal style that instructs TikZ how to place the whole picture on the page.
The trims are needed so that the line width of the rectangles is ignored (they line up exactly on the border of the text area. The baseline
helps to not have empty pages.
The formulas are probably not optimal, I've only figured out a bit too late that I could use the mod
function.
This could still be multiple TikZ pictures where the space between them is controlled by TeX but this is the first solution I've came up with.
Code
\documentclass{article}
\usepackage[margin=1.5cm,landscape,a4paper,showframe]{geometry}
\usepackage{tikz}
\definecolor{dotcolor}{RGB}{204,204,198}
\setlength\parindent{0pt}
% \usepackage{layouts,blindtext}
\tikzset{
maxgrid/dot distance/.initial=+5mm,
maxgrid/dot diameter/.initial=+.8mm,
maxgrid/margin/.initial=+3mm,
maxgrid/minimal column sep/.initial=+10mm,
maxgrid/columns/.initial=3,
maxgrid/@dots/.style={
xstep=\pgfkeysvalueof{/tikz/maxgrid/dot distance}, ystep=+0pt,
line width=\pgfkeysvalueof{/tikz/maxgrid/dot diameter}, line cap=round,
dash pattern=on +0pt off \pgfkeysvalueof{/tikz/maxgrid/dot distance}},
maxgrid/rectangle/.style={draw=dotcolor!70},
maxgrid/dots/.style={draw=dotcolor},
maxgrid/diagram/.style={trim left=+0pt,trim right=+\linewidth,baseline=+1em}}
\newcommand*\tikzmaxgrid[1][]{%
\begin{tikzpicture}[maxgrid/diagram,maxgrid/.cd,#1]
\pgfmathtruncatemacro\tmgDotsPerColumn{
((\linewidth-(\pgfkeysvalueof{/tikz/maxgrid/columns}-1)
*(\pgfkeysvalueof{/tikz/maxgrid/minimal column sep})
)/(\pgfkeysvalueof{/tikz/maxgrid/columns})
-2*(\pgfkeysvalueof{/tikz/maxgrid/margin})
)/(\pgfkeysvalueof{/tikz/maxgrid/dot distance})}
\pgfmathsetlengthmacro\tmgColumnWidth{
\tmgDotsPerColumn*(\pgfkeysvalueof{/tikz/maxgrid/dot distance})
+2*(\pgfkeysvalueof{/tikz/maxgrid/margin})}
\pgfmathsetlengthmacro\tmgColumnWidthExtra{
(\linewidth-(\pgfkeysvalueof{/tikz/maxgrid/columns})*\tmgColumnWidth)
/(\pgfkeysvalueof{/tikz/maxgrid/columns}-1)}
\pgfmathsetlengthmacro\tmgYMargin{
.5*mod(\textheight,\pgfkeysvalueof{/tikz/maxgrid/dot distance})}
\pgfmathsetlengthmacro\tmgYMargin{
\tmgYMargin < \pgfkeysvalueof{/tikz/maxgrid/margin} ?
\tmgYMargin+.5*(\pgfkeysvalueof{/tikz/maxgrid/dot distance}) : \tmgYMargin}
\foreach[parse=true, count=\tmgColumnZero from 0] \tmgColumn in {
1,...,\pgfkeysvalueof{/tikz/maxgrid/columns}}{
\draw[maxgrid/rectangle,
xshift=\tmgColumnZero*(\tmgColumnWidth+\tmgColumnWidthExtra]
(0,0) rectangle ++ (\tmgColumnWidth,\textheight);
\draw[maxgrid/@dots, maxgrid/dots,
xshift=\tmgColumnZero*(\tmgColumnWidth+\tmgColumnWidthExtra,
shift={({\pgfkeysvalueof{/tikz/maxgrid/margin}},\tmgYMargin)}]
(+0pt,+0pt) grid ++(
{\tmgColumnWidth-2*(\pgfkeysvalueof{/tikz/maxgrid/margin})},
{\textheight-2*\tmgYMargin});}
\end{tikzpicture}}
\begin{document}
\tikzmaxgrid[columns=2]
\tikzmaxgrid
\tikzmaxgrid[columns=4, minimal column sep=5mm]
\end{document}
Output
Somewhere between pages 2 and 3:
\columnwid
by hand? The only thing you control by it is the width of each minipage as well as the space between the minipages. The pattern is fixed to the page which makes it annoying to deal with. You could draw a custom dot pattern just by doing\draw[dash pattern=on 0pt off <distance>, line width=<diameter>, line cap=round, ystep=0, xstep=<distance>] (0,0) grid (\textwidth, \textheight);
.remember picture
) and figuring the shift parameters from the relative position on the page, though I would just draw the dots manually (as pergrid
).\columnwid
by hand because if I used0.3\textwidth
it would achieve a similar result, but I would like to have the inner margins (i.e. those seperating the columns) to be a specific width.\columnwid
can be calculated by substracting the margins (*2 for both inner and outer margins) and dividing by 3 (for three columns). I didn't know that the pattern is fixed to the page. The rules for the dots can be found in the parameters (i.e. 5 mm spacing, 0.4 mm thickness). I usedminipages
to achieve the page layout, I'm not sure I can combine it into one Tikz.