I tried many times but failed to draw the graph below using the tikz graphdrawing
library. I am quite confused, especially by its "layouts" concepts.
Problem: How to draw the graph below using graphdrawing
.
Code with graphdrawing
stuff commented:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
% \usetikzlibrary{graphs, graphdrawing}
% \usegdlibrary{layered, force}
\begin{document}
\begin{tikzpicture}[node distance = {1.0cm and 1.5cm}, v/.style = {draw, circle}]
% \graph [spring layout, nodes = {}, horizontal = A to C]
% {
% A -- C -- E,
% B -- {D -- F}
% };
\node (a) [v] {A};
\node (c) [v, right = of a] {C};
\node (e) [v, right = of c] {E};
\draw (a) to node[above] {1} (c);
\draw (c) to node[above] {3} (e);
\node (b) [v, below = of a] {B};
\node (d) [v, right = of b] {D};
\node (f) [v, right = of d] {F};
\draw (b) to node[below] {1} (d);
\draw (d) to node[below] {4} (f);
\draw (a) to node[left] {2} (b);
\draw (c) to node[below] {2} (b);
\draw (c) to node[right] {2} (d);
\draw (e) to node[below] {3} (d);
\draw (e) to node[right] {1} (f);
\end{tikzpicture}
\end{document}
Best Answer
I think you're trying to use
graphdrawing
when you actually should be using the normalgraph
instead. Thegraphdrawing
library is for when you have stuff that follows a structural logic but the graph itself is not of a fixed nature. Quoting Till Tantau:The graph you're proposing, to me, looks like you want to specify where the nodes are, but you want to do it in a concise and powerful way. Quoting Till again:
Here it is how you draw your graph using the
graph
library (no need for Lua):