4

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.

4

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}

enter image description here

The problem is equivalent to

x

\mbox{}

x

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.