2

Is there any latex package to draw graphs by its descriptive relations. Lets say:

\draw_graph_complete{5}{1}

Or

\draw_graph{u,v,x,y,z}{{u,v}{v,x}{x,z}{y,z}}

I don't want to deal with placement coordinates or stuff like that.

So far I have found the tikz libraries as graphs and graphs.standard.

For example this MWE.

\documentclass[a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{graphs, graphs.standard}
\begin{document}
\begin{tikzpicture}
  \graph[nodes={circle, draw}, grow right=2cm, branch down=2cm]{
      b,
      a -- {b,c},
      c -- {b},
      e -- {a,d},
      d -- {c}
  };
\end{tikzpicture}
\end{document}

gives a nice graph, but lacks symmetry in the node b. I can live with that, but looking for alternatives.

2
  • If you want to draw a complete graph or other standard graphs, doesn't graphs.standard do what you need? (I realize it doesn't for the non-standard graph that you provided in your code.) – LarrySnyder610 Apr 28 '19 at 2:46
  • See my answer for the question posted here. Basically, you want to use tikz in combination with the tkz-graph, and tkz-berge packages and you should look into sagetex with Sage. Links are provided to get you started. – DJP Apr 28 '19 at 2:48
3

I think that the question is more how to know which algorithm to employ. I do not have a general answer but in this case you may want to do

\documentclass[a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing, graphs.standard}
\usegdlibrary{force}
\begin{document}
\begin{tikzpicture}
  \graph[spring layout,
nodes={circle, draw}, ]{
      b,
      a -- {b,c},
      c -- {b},
      e -- {a,d},
      d --[orient=90] {c}
  };
\end{tikzpicture}
\end{document}

enter image description here

This places b more symmetrically.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.