[Tex/LaTex] Pushing text below an absolutely positioned box

bounding boxheader-footerpositioningtikz-pgfwatermark

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:

illustration of a simple 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:

where it goes wrong

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}

Best Answer

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}

enter image description here

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}

enter image description here