0

The following mwe is taken from: https://tex.stackexchange.com/a/336315/239572

https://www.latex4technics.com/?note=zzvqvi

\documentclass[border=10pt,multi,tikz]{standalone}
\begin{document}
% adapted from manual 1030
\newbox\mybox
\newcommand*\mysaver{%
  \global\setbox\mybox=\box\pgfpositionnodelaterbox
  \global\let\myname=\pgfpositionnodelatername
  \global\let\myminx=\pgfpositionnodelaterminx
  \global\let\myminy=\pgfpositionnodelaterminy
  \global\let\mymaxx=\pgfpositionnodelatermaxx
  \global\let\mymaxy=\pgfpositionnodelatermaxy
  \pgfmathsetlengthmacro\mylaternodexlength{abs(\mymaxx-\myminx)-\pgflinewidth}%
  \global\let\mylaternodewidth=\mylaternodexlength
}
\newcommand*\myrestorer{%
  \let\pgfpositionnodelatername=\myname
  \let\pgfpositionnodelaterminx=\myminx
  \let\pgfpositionnodelaterminy=\myminy
  \let\pgfpositionnodelatermaxx=\mymaxx
  \let\pgfpositionnodelatermaxy=\mymaxy
  \setbox\pgfpositionnodelaterbox=\box\mybox
}
\def\mylaternode#1;{%
  {%
    \pgfpositionnodelater{\mysaver}
    \node #1;
  }%
}
\def\placemynode(#1,#2){%
  \myrestorer
  \pgfpositionnodenow{\pgfqpoint{#1}{#2}}%
}
\begin{tikzpicture}
  \mylaternode [fill=magenta, blend mode=normal, draw=magenta, fill opacity=.5, draw opacity=.75] (hi) {Hello world};
  \node [top color=blue!50!cyan, bottom color=blue!50!cyan, middle color=white, minimum height=20mm, minimum width=\mylaternodewidth, draw=blue!50!cyan] at (10mm,10mm) {};
  \placemynode(10mm,10mm)
\end{tikzpicture}
\end{document}

How can I expand it in order to generalize the \mylaternode and \placemynode so that I can create and place multiple nodes later? The cleanest way is imho to make use of the node name (hi), but I actually have no idea about the syntactical possibilities of latex, which is why I ask for help

Edit: The reason for asking the question is that I have a bunch of nodes that differ in size and sometimes overlap. I want to place them according to their rendered sizes. The node contents are read from a csv file

The approach "left/right=of othernode" does not seem to suffice since they are already placed in relation to a third node.

e.g.

\node (a) {a};
\node (b) at ($(a)+(1,0)$) {b};
\node (c) at ($(a)+(1.5,.5)$) {c};

due to the nodes size a+(1.5,.5) overlaps with a+(1,0)

for most of the nodes placed in that manner the problem does not occur, hence the question persists for the overlapping rest of them

  • 2
    Is this related to your earlier questions about layers? I'm asking because it might be that there is a simpler way of getting your desired result. If you can clearly describe your use case, maybe with a mock-up screenshot or an example from an existing document that you have seen before, then it will be easier to find the right solution. – Marijn Apr 14 '21 at 16:06
  • no its not related to the layers but thx for asking and keeping track :D It should not be that hard to adapt the mwe, should it? – user239572 Apr 14 '21 at 16:41
  • Maybe this MWE can be made to work with multiple nodes, but it seems a rather complicated approach, which should not be necessary for most usage scenarios. Therefore I was curious what you actually want to do, maybe a different/easier setup would be applicable as well. – Marijn Apr 14 '21 at 18:44
  • 1
    I second that. It is most likely that you get help by describing exactly what you want instead of asking us to adapt an answer to another possibily unrelated question. – SebGlav Apr 14 '21 at 21:15
  • see edit (no mwe) – user239572 Apr 15 '21 at 05:45
  • Thanks for the update. I still don't fully understand it though, if two nodes overlap then they will also overlap when you place one later, right? – Marijn Apr 15 '21 at 20:55

0 Answers0