Graphics, Figures & TablesTikZ determine coordinate of a node

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
woltan
Posts: 19
Joined: Mon Mar 09, 2009 2:08 pm

TikZ determine coordinate of a node

Post by woltan »

Heyas,
I have the following problem:
I have a series of nodes within a foreach statement. They are being drawn on a vertical line, but all have different widths.
How do I determine the node that reaches the furthest out to the left?

I know that there is the "let" path operation, with which I can get the x-coordinate of every node but I can only draw stuff and not memorize the x-coordinates to compare them after the foreach to find the lowest x.

Is there any other way to determine the x-coordinate of a node?

Thx for any hint, suggestion etc!
cherio Woltan

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

fenn
Posts: 5
Joined: Sun Jul 05, 2009 9:21 pm

TikZ determine coordinate of a node

Post by fenn »

This may not be helpful to you, but if you are looking to define a shape that encompasses all nodes, you can use the fit parameter when defining a node.

Code: Select all

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{fit}

\begin{document}

\begin{tikzpicture}

	\node (polarizer) at (0,1) [draw,rectangle,minimum width=1cm]{};
	\node (quarter wave) at (0,2) [draw,rectangle,minimum width=3cm]{};
	\node (box) [draw,rectangle,dotted, inner sep=2mm,fit = (polarizer) (quarter wave)]{};

\end{tikzpicture}

\end{document}
In this example, the (box) node will be drawn such that all specified nodes fit within it.
Last edited by fenn on Wed Jan 20, 2010 3:30 pm, edited 1 time in total.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: TikZ determine coordinate of a node

Post by localghost »

The same applies to solutions as well as to requests. Complete examples are most helpful.


Best regards
Thorsten
fenn
Posts: 5
Joined: Sun Jul 05, 2009 9:21 pm

Re: TikZ determine coordinate of a node

Post by fenn »

Fair enough. I've updated my post with a properly working example.
Post Reply