# Curious about TikZ [remember picture,overlay] spacing

When I use \tikz[remember picture,overlay] there is vertical space inserted wherever the command is used, as in the following:

\documentclass{article}

\usepackage{tikz}
\usepackage{lipsum}

\begin{document}

\tikz[remember picture,overlay]\node[rectangle, minimum size=5cm,fill=lightgray]
(X) at (current page.center) {};

\lipsum[1]

\tikz[remember picture,overlay]\node[rectangle, minimum size=5cm,fill=lightgray]
(X) at (current page.center) {};

%% Fixes the problem:
% \kern-\baselineskip

\lipsum[2]

\end{document}


There is a baseline skip before the first paragraph and between the first and second paragraphs. I can't find anything in the documentation that hints at this. In fact, on page 248 (Manual for Version 3.0.1a) there is this for overlay: "The effect of this option is that everything within the current scope is not taken into consideration when the bounding box of the current picture is computed." That led me to believe that the option would be spacing-neutral.

I'm using MacTeX2015 with the latest updates.

Insights welcome.

The problem isn't tikz. It is the blank lines between the \tikz macros and the subsequent \lipsum macros. LaTeX takes the blank line as a paragraph break. A few well-placed % signs fixes it.

\documentclass{article}

\usepackage{tikz}
\usepackage{lipsum}

\begin{document}

\tikz[remember picture,overlay]\node[rectangle, minimum size=5cm,fill=lightgray]
(X) at (current page.center) {};%
%
\lipsum[1]

\tikz[remember picture,overlay]\node[rectangle, minimum size=5cm,fill=lightgray]
(X) at (current page.center) {};
%
%% Fixes the problem:
% \kern-\baselineskip
%
\lipsum[2]

\end{document}


The problem is equivalent to

x

\mbox{}

x


producing 2, rather than 1, paragraph breaks, even though \mbox{} doesn't print anything.