I'd like to insert a grid to fill the whole picture. I'm trying to mimic a blueprint paper.
So, I have two questions:
- Why the use of colored rectangle change the border around picture?
- Why the grid is much bigger than the picture size? In some sense, the anchors are not working.
Edit: using the current bounding box
as suggested by Phelype Oleinik, the grid is over the draw. But the space around produced by the background rectangle is out of the grid.
MWE
% !TeX program = pdflatex
\documentclass[border=0]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}[
background rectangle/.style={fill=green},
show background rectangle, %% <-- insert space around
]
\draw (0,0) -- (3,4) -- (0,3) -- cycle;
\draw[white,step=.5cm] (current bounding box.south west) grid (current bounding box.north east);
\end{tikzpicture}
\end{document}
\draw[white,step=.5cm] (current bounding box.south west) grid (current bounding box.north east);
. That is, use the picture'scurrent bounding box
instead of thecurrent page
.backgrounds
library defines theshow background rectangle
as\tikzstyle{show background rectangle}=[execute at end picture=\tikz@background@framed]
, which does the framing after the picture is created and the bounding box is set, that's why the grid does not span the outer rectangle. You could use something to enlarge the bounding box prior to the end of the picture, then draw the grid...