# TikZ whitespace between nodes [duplicate]

Possible Duplicate:
TikZ borders showing through when they shouldn't (overlapping circles)

Using absolute positioning I can make a nice filled grid:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\newcommand{\backgroundfill}[5]{
\begin{tikzpicture}[remember picture, overlay]
\node (rect) at (current page.north west)
[shift={(#3/2 + #1, -#4/2 - #2)},
minimum width =#3,
minimum height=#4,
fill=#5] {};
\end{tikzpicture}
}

\thispagestyle{empty}
\begin{document}
\newlength{\LX}
\setlength{\LX}{.5\paperwidth}
\backgroundfill{0cm}{0cm}{\LX}{\LX}{black}
\backgroundfill{\LX}{0cm}{\LX}{\LX}{blue}
\backgroundfill{0cm}{\LX}{\LX}{\LX}{blue}
\backgroundfill{\LX}{\LX}{\LX}{\LX}{black}
\end{document}


As I zoom into the image however, I sometimes notice the white background between rectangles. It's small but noticeable on the screen but for some reason does not show up on the uploaded PDF (the rasterized picture above). To convince myself that it was real, I took a screenshot and zoomed in on the border where the edge effect is clearly apparent.

Is there any way to avoid the whitespace between rectangles in TikZ?

-
I can't reproduce this. What viewer are you using? It might help if you just put one big black (or blue) rectangle behind your pattern to avoid the white background showing through. –  Jake Sep 19 '12 at 20:12
@Jake I'm using evince on a stock Ubuntu setup. I can't just put a solid background behind the rectangle since I like this to generalize to multiple (4) colors at each border. –  Hooked Sep 19 '12 at 20:19
@Jake I also get the same result if I open up the pdf with gimp. The higher the pixels per inches (resolution) the smaller the effect, but it's still there. –  Hooked Sep 19 '12 at 20:21

## marked as duplicate by Paul Gaborit, Gonzalo Medina, Marco Daniel, Tom Bombadil, egregSep 21 '12 at 22:50

First I would avoid accumulating rounding errors by unnecessary spaces. pgf first determines the current position of \backgroundfill because of option remember picture. The next \backgroundfill is moved to the right because of spaces by line ends. The .aux file contains the positions (the numbers are the horizontal and vertical position with unit sp):

\pgfsyspdfmark {pgfid1}{9782558}{43234099}
\pgfsyspdfmark {pgfid2}{10437917}{43234099}
\pgfsyspdfmark {pgfid3}{11093276}{43234099}
\pgfsyspdfmark {pgfid4}{11748635}{43234099}


The code without the unnecessary white spaces:

\documentclass[a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\newcommand{\backgroundfill}[5]{%
\begin{tikzpicture}[remember picture, overlay]
\node (rect) at (current page.north west)
[shift={(#3/2 + #1, -#4/2 - #2)},
minimum width =#3,
minimum height=#4,
fill=#5] {};
\end{tikzpicture}%
}

\thispagestyle{empty}
\begin{document}
\newlength{\LX}
\setlength{\LX}{.5\paperwidth}
\backgroundfill{0cm}{0cm}{\LX}{\LX}{black}%
\backgroundfill{\LX}{0cm}{\LX}{\LX}{blue}%
\backgroundfill{0cm}{\LX}{\LX}{\LX}{blue}%
\backgroundfill{\LX}{\LX}{\LX}{\LX}{black}%
\end{document}


The new positions:

\pgfsyspdfmark {pgfid1}{9192734}{46450400}
\pgfsyspdfmark {pgfid2}{9192734}{46450400}
\pgfsyspdfmark {pgfid3}{9192734}{46450400}
\pgfsyspdfmark {pgfid4}{9192734}{46450400}


Caution: TikZ does not warn if its data in the .aux file has changed. Even without a rerun warning, an additional run might be needed. Package rerunfilecheck helps to get a warning, if the .aux file has been changed:

\usepackage[aux]{rerunfilecheck}


Then the .pdf file, generated by pdflatex contains the following rectangles:

-139.74774 -161.87898 297.64163 297.64163 re
157.89388 -161.87898 297.64163 297.64163 re
-139.74774 -459.52061 297.64163 297.64163 re
157.89388 -459.52061 297.64163 297.64163 re


The operator re has the following syntax:

<x-pos> <y-pos> <width> <height> re


Right edge of the left boxes: 157.89389 = -139.74774 + 297.64163
Left edge of the right boxes: 157.89388
Lower edge of the box above: -459.52091 = -161.87898 - 297.64163
Upper edge of the box below: -459.52061

That means there is already a tiny overlapping by 0.00001bp and 0.0003bp.

Trying different PDF viewers, I could not see the gaps.

-
This is incredibly helpful in my understand of what goes on behind the scenes. Thank you! How did you determine from the PDF the rectangle coordinates? –  Hooked Sep 20 '12 at 2:48
A good and detailed analysis... but this is irrelevant here. Even without rounding errors and with perfect values in the PDF file, the aliasing artifact may still visible. –  Paul Gaborit Sep 20 '12 at 6:24
@PaulGaborit Yes, I could reproduce the problem with gs -r72 -dTextAlphaBits=4 -dTextGraphicsBits=4 -dBATCH test.pdf. –  Heiko Oberdiek Sep 20 '12 at 8:50

As a poor-man's fix, changing the following lines:

minimum width =#3,
minimum height=#4,


to:

minimum width =1.001#3,
minimum height=1.001#4,


"overdraws" the rectangles enough so the background is never visible. I'm still not quite sure why my viewer evince renders the background when there is no interleaving space, so the question is still open.

-
I'm pretty sure that this is an aliasing artifact. We had a few questions here but I couldn't find it. Oops here it is tex.stackexchange.com/questions/49614/… –  percusse Sep 19 '12 at 20:31