Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw a graph in LaTeX?

First of all, let me say I'm using LyX, though I have no problem using ERT.

Secondly, what is the most simplest way to draw a simple graph like this in Latex? alt text

I've seen some documents with graphs and I've seen some examples, but I couldn't figure out how to just draw a simple graph - what packages do I need, etc?

like image 569
Amir Rachum Avatar asked Jun 06 '10 19:06

Amir Rachum


People also ask

Can we draw graph in LaTeX?

We can now discuss the packages that we can use to draw graphs in LaTeX. The most common LaTeX package used for drawing, in general, is TikZ, which is a layer over PGF that simplifies its syntax.


2 Answers

TikZ can do this.

A 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} 

produces:

enter image description here

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

More information about TikZ: http://sourceforge.net/projects/pgf/ where I guess an installation guide will also be present.

like image 77
Bart Kiers Avatar answered Sep 24 '22 01:09

Bart Kiers


Aside from the (excellent) suggestion to use TikZ, you could use gastex. I used this before TikZ was available and it did its job too.

like image 36
Pieter Avatar answered Sep 21 '22 01:09

Pieter