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.)

Oberon
  • 171
  • 3

2 Answers2

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

Salim Bou
  • 17,021
  • 2
  • 31
  • 76
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.

Enlico
  • 2,592