I have a problem, I'm a master student, and I'm writing my thesis (graph theory) in LaTeX.

Can anyone help me to find an online website to draw graphs and then insert the code in LaTeX online?

  • 1
    @Skillmon I think the OP wants a graph of tikz nodes not a graph in the sense of a function plot. – David Carlisle May 1 '17 at 20:37
  • TikZ has its own graphdrawing library with Lua backend. – percusse May 1 '17 at 21:01
  • 1
    Can you show an example of what kind of graphs you are talking? – user36296 May 1 '17 at 22:08
  • You can do simple graph theory graphs one point at a time using DIA. sourceforge.net/projects/dia-installer/?source=typ_redirect Or you can use R and knitr with R's graph theory libraries. In both cases you get Tikz code which is basically not human readable. A far better choice is to just learn how to create graph theory diagrams directly in Tikz code. And to assist read tcs.uni-luebeck.de/downloads/mitarbeiter/tantau/… – R. Schumacher May 1 '17 at 22:30

Here is an example of using the igraph package in R and embedding the result in a pdf file using knitr and pdflatex. Depending upon your operating system and setup the actual workflow details may vary.

In general, 1) create the latex file with the embedded R commands. Save this with the extension *.Rnw (case sensitive) 2) now use R to run the knit command on this *.Rnw file. You will not get an *.tex file with the same base name as the original *.Rnw file. 3) Run pdflatex and then view the *.pdf file.

Here is an example source file (extracted from http://www.r-graph-gallery.com/247-network-chart-layouts/).

Demo of Graph Theory using R and Tikz
# library

# Create data
data=matrix(sample(0:1, 400, replace=TRUE, prob=c(0.8,0.2)), nrow=20)
network=graph_from_adjacency_matrix(data , mode='undirected', diag=F )

# When ploting, we can use different layouts:
par(mfrow=c(2,2), mar=c(1,1,1,1))
plot(network, layout=layout.sphere, main="sphere")
plot(network, layout=layout.circle, main="circle")
plot(network, layout=layout.random, main="random")
plot(network, layout=layout.fruchterman.reingold, main="fruchterman.reingold")

And results in

enter image description here


You might consider signing up for a free Sagemath Cloud account which gives you the power of the computer algebra system Sage along with the sagetex package in LaTeX; documentation here. Sage has knowledge of graph theory; for example named graphs, graph parameters, and even LaTeX options. That means you can create your graphs using tikz or use the power of Sage to take care of the details. Here's an example:

Here's a graph where you specify the position of the vertices. Note that  the label is placed inside unless specified:\\\\
\renewcommand*{\VertexLineWidth}{1pt}%vertex thickness
\renewcommand*{\EdgeLineWidth}{1pt}% edge thickness
\Edge (R3)(R4)
\Edge (R3)(R1)
\Edge (R2)(R3)
\Edge (R5)(R4)
\Edge (R5)(R6)
\Edge (R5)(R7)
\Edge (R6)(R8)
\Edge (R7)(R8)

But \textsf{Sage} has knowledge of graph theory and you can use it to specify graphs
and determine various characteristics. For example:\\\\
H= graphs.PetersenGraph()
Chi = H.chromatic_number(algorithm="DLX")
Beta = H.independent_set()
\noindent The Petersen graph below has $\sage{H.order()}$ vertices and
$\sage{H.size()}$ edges.\\\\
\SetVertexNormal[Shape=circle,LineWidth = 1pt]
\tikzset{EdgeStyle/.append style = {color = blue!60, line width=1pt}}
The chromatic number is $\chi(G)=\sage{Chi}$. The maximum size independent 
set is $\beta(G)=\sage{len(Beta)}$. One such set is $\sage{Beta}$. The 
maximum size clique has $\omega(G)=\sage{H.clique_number()}$ vertices; 
e.g., $\sage{H.clique_maximum()}$. The diameter is $\sage{H.diameter()}$
and the radius is $\sage{H.radius()}$.

The result running in Sagemath Cloud is:enter image description here

If you zoom in on the picture you'll find that Sage has calculated the parameters of the graph for you---a good way to avoid mistakes in an important document.


You can export anything drawn in Geogebra as tikz code, see this tutorial, https://www.sharelatex.com/blog/2013/08/28/tikz-series-pt2.html

  • 1
    Welcome to TeX.SX! Linked pages tend to disappear, it would be better to add some word of explanation in the answer. – egreg Oct 10 '17 at 14:36

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.