# Pushing text below an absolutely positioned box

I'm trying to create a document header, part of which is an absolutely positioned TikZ picture, and part of which is some text in a TikZ node. The northwest or northeast anchor of the node should be at a specific point in the picture, but I also want LaTeX to recognize that the main text of the document should remain below the node. Is there a way to do that?

That description probably wasn't too clear, so here's an example:

The black lines at top and left are the edges of the page; they mean nothing. In this image, the blue box is absolutely positioned using the overlay option. I want to find some way to absolutely position the red box so that the red dot falls in the same location on the page as the blue dot. (i.e. the blue box is just a marker identifying the point on the page where I need the other box to appear.) I can do it using the overlay option for that node as well, but then the main text (lipsum) overlaps the red box, like this:

If the red node included another line of text it would be even more obvious.

I want the main text to remain below the red box, as it does in the first image, even while the red box is aligned to the proper absolute point on the page, as in the second image. Any ideas on how to do that?

I'm open to solutions that involve creating an additional, empty TikZ picture to serve only as a bounding box, or creating some other kind of box to fill that role, or adjusting one of LaTeX's builtin lengths (which I'm only vaguely familiar with, but if that's what it takes, I'll figure it out), or anything else. If it's as simple as using \vspace, then the question becomes, how can I calculate the height of the red box to determine how much space needs to be inserted? The content of the red box is variable, and in particular can be of variable height, and it will not be practical to manually adjust the amount of \vspace inserted each time.

I've looked at a few other questions that mention wrapping around an absolutely positioned box, like this one, but my situation is a little different because I'm not trying to adjust the width of a line, only insert some amount of vertical space (effectively), which I think should be more doable.

Here's the MWE code for the first image:

\documentclass{article}
\usepackage{lipsum,tikz}
\usepackage[margin=1in]{geometry}

\begin{document}
\begin{tikzpicture}[shift={(current page.north west)},shift={(1in,-1in)},
remember picture,overlay]
\coordinate (my spot) at (0,0);
\fill[blue] (my spot) circle (1mm);
\node[above right,align=left,blue,draw=blue,thick] at (my spot)
{I want the red text to appear\\right below this box};
\end{tikzpicture}

% to make second pic, remove \noindent and add overlay option
\noindent\begin{tikzpicture}[remember picture]
\fill[red] (my spot) circle (1mm);
\node[below right,align=left,red,draw=red,thick] at (my spot)
{the red dot should go where the blue dot is\\
lipsum should remain below this red box};
\end{tikzpicture}

\lipsum
\end{document}

• Do you want to keep the bottom part of the page untouched, inother words, should the text height change according to the header height? Nov 26 '13 at 16:53
• @percusse yes, if the header height is increased, the text height should decrease by the corresponding amount so that the bottom margin remains the same. Nov 26 '13 at 17:07

Here is one option:

Don't use overlay at all.

\documentclass{article}
\usepackage{lipsum,tikz}
\usepackage[margin=1in,showframe]{geometry}

\begin{document}
\noindent
\hspace*{-2mm}
\begin{tikzpicture}
\coordinate (my spot) at (0,0);
\fill[blue] (my spot) circle (1mm);
\node[above right,align=left,blue,draw=blue,thick,outer sep=0pt] at (my spot)
{I want the red text to appear\\right below this box};
\fill[red] (my spot) circle (1mm);
\node[below right,align=left,red,draw=red,thick,outer sep=0pt] at (my spot)
{the red dot should go where the blue dot is\\
lipsum should remain below this red box};
\end{tikzpicture}

\lipsum
\end{document}


And option 2:

overlay really overlays. Hence main text will not know where that picture comes. You have to manually adjust the distances.

\documentclass{article}
\usepackage{lipsum,tikz}
\usepackage[margin=1in,showframe]{geometry}

\begin{document}
\begin{tikzpicture}[shift={(current page.north west)},shift={(1in,-1in)},
remember picture,overlay]
\coordinate (my spot) at (0,0);
\fill[blue] (my spot) circle (1mm);
\node[above right,align=left,blue,draw=blue,thick,outer sep=0pt] at (my spot)
{I want the red text to appear\\right below this box};
\end{tikzpicture}

% to make second pic, remove \noindent and add overlay option
\noindent\begin{tikzpicture}[remember picture,overlay]
\fill[red] (my spot) circle (1mm);
\node[below right,align=left,red,draw=red,thick,outer sep=0pt] at (my spot)
{the red dot should go where the blue dot is\\
lipsum should remain below this red box};
\end{tikzpicture}

\vspace*{.5\baselineskip}    %% use appropriate length
\lipsum
\end{document}


• Thanks for the attempt, but option 1 won't work for me as it doesn't allow me to achieve the required absolute positioning. Option 2 is more promising but then, as I mentioned in the question, the issue is: how do I calculate the appropriate length to put in \vspace? (I've clarified these points in an edit to the question, for future answerers.) Nov 26 '13 at 15:44
• In principle one could use \pgfextracty to get the height of the red bounding box. But when I tried using the second example, I get an error saying dimension is too large... :( Nov 27 '13 at 5:23
• @KevinC hm, well if anyone could find a way to get around that problem, I think that might just be the solution I'm looking for. Nov 30 '13 at 5:13
• @KevinC it seems like overlay disables the bounding box calculation
– vqv
Aug 26 '14 at 18:56