7

I have the following code:

\documentclass[tikz]{standalone}
\usetikzlibrary{graphs}
\begin{document}
\tikz \graph[grow right sep=20,nodes={draw,rectangle}] { a -> {b, long node name} };
\end{document}

Which produces this output: MWE output: a -> {b, long node name}

I'd like to have the edge "a" -> "long node name" to not go from east to north but from south to west. Is this possible while still using just one \graph call? Or do I need to specify that edge manually in an extra command?

(That is, I have basically the same problem as in the question Edge anchor in tikz, but I want to use TikZ' graph drawing capabilities instead of manually creating edges.)

0

2 Answers 2

5

To obtain west anchor for node long node name you can use right anchor=west.

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{graphs}
\begin{document}
\tikz \graph[grow right sep=20,nodes={draw,rectangle},right anchor=west] { a -> {b, long node name} };
\end{document}

Result

enter image description here

1
  • The arrows should go from south to west, though. :)
    – Alenanno
    Commented Feb 7, 2016 at 11:04
1

This is what you want, I think. enter image description here

I never used \graph. The natural way I do something like what you asked is using \nodes and anchors, as follows:

\documentclass[tikz]{standalone}
\usetikzlibrary{graphs}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
    \node[draw] (a) {a};
   \node[draw,anchor=west] (b) at ($(a)+(1cm,0)$) {b};
   \node[draw,anchor=west] (c) at ($(a)+(1cm,-1cm)$) {long node name};
   \draw[->] (a) -- (b);
   \draw[->] (a.south) -- (c.west);
\end{tikzpicture}
\end{document}

Sure, you have to set a proper distance between the nodes; if not so, the arrow head could intersect the rectangle, but there's no way to avoid this but changing arrow heads. Furthermore, you could use curved arrows.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .