How to draw a graph in LaTeX?

First of all, let me say that I am using LyX, although I have no problem using ERT.

Secondly, what is the easiest way to make a simple graph like this in Latex? alt text

I saw some documents with graphs, and I saw some examples, but I could not understand how easy it was to draw a simple graph - which packages I needed, etc.

+69
graph-theory latex lyx
Jun 06 '10 at 19:03
source share
6 answers

TikZ can do this.

Quick demo:

\documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} [scale=.8,auto=left,every node/.style={circle,fill=blue!20}] \node (n6) at (1,10) {6}; \node (n4) at (4,8) {4}; \node (n5) at (8,9) {5}; \node (n1) at (11,8) {1}; \node (n2) at (9,6) {2}; \node (n3) at (5,5) {3}; \foreach \from/\to in {n6/n4,n4/n5,n5/n1,n1/n2,n2/n5,n2/n3,n3/n4} \draw (\from) -- (\to); \end{tikzpicture} \end{document} 

gives:

enter image description here

Other examples @ http://www.texample.net/tikz/examples/tag/graphs/

Additional information on TikZ: http://sourceforge.net/projects/pgf/ , where I assume that an installation guide will also be present.

+98
Jun 06 2018-10-06T00:
source share

Perhaps use tikz .

+2
Jun 06 '10 at 19:08
source share

Besides the (excellent) suggestion to use TikZ, you can use gastex . I used this before TikZ was available, and it was doing its job too.

+2
Jun 06 2018-10-06T00:
source share

I used Graphviz ( https://www.graphviz.org/gallery ) along with latex, using the dot command to create graphics in PDF and includegraphics to include them.

If graphviz produces what you aim for, this might be the best way to integrate: dot2tex: https://ctan.org/pkg/dot2tex?lang=en

+2
Jun 06 2018-10-06T00:
source share

In my experience, I always use an external program to generate a graph (math, gnuplot, matlab, etc.) and export the graph in pdf or eps format. Then I include it in the document with includegraphics .

0
Jun 06 '10 at 19:07
source share

Here is a handy tool that you can use to draw graphs: http://www.madebyevan.com/fsm/

0
Jan 24 '19 at 6:08
source share



All Articles