# what is a quick generic way to draw graphs (in the graph theory sense)?

I am looking for a very simple way to write a command for drawing (undirected or direct) graphs in Latex. I am aware of tikz, but it is an overkill for what I want, especially since I want the .tex file to have easy to understand logical form.

All I want is to specify a set of nodes (or just the number of nodes), a possible label for some of the nodes, and the set of edges. $G=(V,E)$ in the usual sense with labelings for $V$.

I don't mind too much what the graph looks like as long as it is logically correct.

EDIT: For example, I would specify a graph using:

  \begin{undirectedgraph}
\Nodes[5]{a,b,c,d,e}
\Edge{1,5}
\Edge{4,3}
\end{undirectedgraph}


and that would draw a graph with 5 nodes, labeled a-e with edges between vertex 1 and 5 and 4 and 3.

• Perhaps with the psmatrix environment (from pst-node): you first describe the vertices as nodes in a matrix of nodes, then you describe the edges as links between some pairs of nodes. One advantage of pstricks syntax is that it is latex-like, and nowadays it can be compiled with pdflatex. Commented Oct 11, 2014 at 22:28
• It would be helpful if you specified exactly how you want to specify the set of nodes and edges. Much of the work involved in this is really just that as that is going to determine how much flexibility you desire. Commented Oct 11, 2014 at 22:33
• @PeterGrill I added an edit about that. Commented Oct 12, 2014 at 6:32

Not sure why TikZ is considered overkill. The following looks quite straight forward, although it requires LuaLaTeX:

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{graphs,graphdrawing,arrows.meta}
\usegdlibrary{circular}
\begin{document}
\tikz[>=Stealth]\graph [simple necklace layout, nodes={circle, draw}, node sep=1cm]{
a, b, c, d, e;
a -> e;
d -> c;
};
\end{document}


• this looks rather simple. I was unaware that you can create graphs that easily in tikz. Commented Oct 12, 2014 at 12:13
• @kloop note this requires the latest PGF/TikZ release. Commented Oct 12, 2014 at 12:16

I've had good luck making diagrams using graphviz and then importing those graphics. Below is from the web page and there is a gallery with source.

The Graphviz layout programs take descriptions of graphs in a simple text language, and make diagrams in useful formats, such as images and SVG for web pages; PDF or Postscript for inclusion in other documents; or display in an interactive graph browser. Graphviz has many useful features for concrete diagrams, such as options for colors, fonts, tabular node layouts, line styles, hyperlinks, and custom shapes.