Consider this MWE:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[remember picture,overlay]
\node [circle, fill=red!90!black, minimum width=15em] at (current page.center) {};
\end{tikzpicture}
\section{Amazing movable type!}
\end{document}
The section title is moved even though the picture with overlay should take up no space. Try inputting just a section title without tikzpicture
, and notice that there is less vertical space above section title:
\documentclass{article}
\begin{document}
\section{Amazing movable type!}
\end{document}
or see illustration:
The behavior is the same with comments which should eat up spaces:
\documentclass{article}
\usepackage{tikz}
\begin{document}%
%
\begin{tikzpicture}[remember picture,overlay]%
\node [circle, fill=red!90!black, minimum width=15em] at (current page.center) {};%
\end{tikzpicture}%
%
\section{Amazing movable type!}
\end{document}
I noticed that extra vertical space is added when:
- tikzpicture is inputted before
section
titles - tikzpicture is inputted before
description
environment - tikzpicture is inputted before
itemize
environment - tikzpicture is inputted before
enumerate
environment
Tikzpicture behaves as expected with normal text. For example, this will work fine:
\documentclass{article}
\usepackage{lipsum, tikz}
\begin{document}
\section{Amazing movable type!}
\begin{tikzpicture}[remember picture,overlay]
\node [circle, fill=red!90!black, minimum width=15em] at (current page.center) {};
\end{tikzpicture}%but you must not leave some space here, otherwise, a single blank space is shown before text.
\lipsum[13]
\end{document}
Why is that happening and how can it be prevented? The \useasboundingbox (0,0);
suggestion from Make tikz picture floating does not help.
edit
Caramdir's suggestion to input\nointerlineskip
before tikzpicture
seems to fix vertical space issue for section titles, but descriptions and similar environments still have undesired extra vertical space. See illustration:
tikzpicture
does seem to always switch to horizontal mode so that the blank lines before and after are interpreted as paragraph breaks. Commenting them out should help.zref
s\zlabel
s and Heiko Oberdiek told me that such things can't be placed into the document without disturbing the spacing. At least that's the way I understood it. However, he uses the LaTeX space hack around it, which doesn't help that much in vertical mode.\@bsphack .. \@esphack
) doesn't work here. It actually raises an error. The same space appears when you replace thetikzpicture
with a\marginpar
. Also placingtikzpicture
inside a\vbox to 0pt{.. \vss}
doesn't help. This seems to be a tricky issue which requires someone with deep knowledge of TeX.\nointerlineskip
before thetikzpicture
solves the problem, except at the beginning of the document (where an additional paragraph seems to be inserted somewhere).