Graphics, Figures & TablesControlling lines in tikz

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Kotoschow
Posts: 28
Joined: Mon Apr 09, 2012 3:13 pm

Controlling lines in tikz

Post by Kotoschow »

Hi all,

I am trying to draw a tikz diagram with nodes and lines. I would like to control the point where lines meet nodes. That is, for some node whose coordinates are (x,y), I want to be able to draw lines that start at (x,y+0.2) and terminates at (x,y-0.2). That is, I want a shortcut for the following commands:

Code: Select all

\node(a) at (0,0);
\node(b) at (1,1);
\draw(0,.2) -- (1,.8);

Is there any command which gives me the coordinates of a node? Or an optional argument for the \node command which tells the node where lines should meet it?

Thanks!

Recommended reading 2024:

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

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

Controlling lines in tikz

Post by Stefan Kottwitz »

The easiest:

Code: Select all

\draw (a.north) -- (b.south);
With shifts:

Code: Select all

\draw ([yshift=0.2ex]a.north) -- ([yshift=-0.1ex]b.south);
Adding arbitrary x and y coordinates:

Code: Select all

\usetikzlibrary{calc}% in the preamble
...
\draw ($(a) + (0,.2)$) -- ($(b) - (0,0.2)$);
Stefan
LaTeX.org admin
Post Reply