Subscribe

how to get single x/y-coordinates from nodes Monitor

1. 2008-06-17 06:58:47 PDT
Hello,

I browsed through the manual, mailing lists and the web, but could not find an answer, so I post my question here.

Is there an easy way with TikZ or PGF to get either the x or the y-coordinate from a named node?

I'd like to achieve this:
I have a set of named nodes, and I want to create a new node that is 1. centered horizontally (= the new node's x-coordinate is halfway between the leftmost and the rightmost nodes' x-coordinate), and 2. just above the highest source node (= the new node's y-coordinate is the maximum of all other nodes plus some fixed offset). So I need to do computations with these nodes' coordinates, but separately and differently for the x- and y-coordinate.

How could I do such a thing, without digging too deep into the core functionality of PGF?

Peter
2. 2008-06-17 07:18:53 PDT
Hi,

Fooling around with coodinates is the hard way, but you could say

\newdimen\myx
\pgfextractx\myx{\pgfpointanchor{node name}{center}}

and similarly for y. However *much* easier (assuming I understand what you want) is to cheat and use the fit library to create a node around the required nodes and then reference that node for the label:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit,positioning}
\begin{document}
\begin{tikzpicture}

\foreach \x in {a,b,c,d,e,f,g,h}
\node [circle, draw] (\x) at (rand*3cm,rand*3cm) {\x};

\node[draw,inner sep=0pt, help lines,dotted, rectangle, fit=(a) (b) (c) (d) (e) (f) (g) (h)] (box) {};
\node[above=1cm of box.north]{label};

\end{tikzpicture}
\end{document}

-Mark

3. 2008-06-17 08:52:00 PDT
Thank you very much, the fit library can do exactly what I need. I guess I have been looking in the wrong sections of the manual (system layer etc.) for a solution...

Thanks,
Peter
< Previous | 1 | Next >

This forum does not allow anonymous participation.

Log in to add a reply. Not registered? Create an account to participate and receive email updates when replies are posted to this topic.