I've been using LaTeX since three years, but I've always avoided the Tikz package for drawing. Now I am writing my degree thesis and I'm forced to use it to achieve a better result. The problem is just I don't have time right now to start a deep walkthrough.

I have to draw these simple patterns of graphs: a triangle and a complete bipartite graph (see pictures below). I found the sample code of a simple triangle graph on the web and I tried to rearrange nodes using relative positioning, but the result was not quite good. This is my attempt.

\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,
        thick,main node/.style={circle,fill=blue!20,draw,minimum size=1cm,inner sep=0pt]}]

    \node[main node] (1) {$1$};
    \node[main node] (2) [below left of=1]  {$2$};
    \node[main node] (3) [below right of=1] {$3$};

    (1) edge node {} (2)
        edge node {} (3)
    (2) edge node {} (1)
        edge node {} (3)
    (3) edge node {} (1)
        edge node {} (2);

Could you please give me any help to improve this result?

Thank you.

Graph pattern

  • 17
    @downvoters: Please don't pile on downvotes. A net score of -1 is enough to show that the question needs to be improved. More downvotes should be reserved for questions that are unsalvageable or spam. Feb 7, 2014 at 15:04
  • 3
    I think your question is reasonable and you've shown some effort, especially compared to some of the others that we have seen on the site. The down-voting policy can be pretty inconsistent, it really depends on who is looking at it; looks like you're on the way up now :) I think it was probably the line when you said The problem is just I don't have time right now to start a deep walkthrough. that might have set the tone for some folks.
    – cmhughes
    Feb 7, 2014 at 16:56
  • @cmhughes You're completely right! Well, maybe the downvoters didn't understand the meaning of I don't have time right now to start a deep walkthrough. To me this means that I tried to edit the code found on the web but I failed due to my poor Tikz background. I'm really interested in this package and I'm surely going to learn it in the future.
    – Driu
    Feb 7, 2014 at 17:50
  • 3
    For what it's worth, I don't think anyone learns TikZ by doing a deep walkthrough. It's not something you sit down and dedicate time to study. People learn TikZ bit by bit, as needed, in order to create good-looking pictures. So I think what you're doing now is the perfect way to start learning. Just start with the goal of making a diagram, and then learn whatever little piece of TikZ syntax you need to in order to do it. Then repeat as necessary.
    – David Z
    Feb 7, 2014 at 18:27

5 Answers 5


Well, we answer many questions with "Do it for me!" Why not this one!

TikZ mafia here won't forgive people having no time to learn tikz;). The code you got from elsewhere makes wrong use of below of. This is how it is used with positioning library.

\tikzset{main node/.style={circle,fill=blue!20,draw,minimum size=1cm,inner sep=0pt},
    \node[main node] (1) {$1$};
    \node[main node] (2) [below left = 2.3cm and 1.5cm of 1]  {$2$};
    \node[main node] (3) [below right = 2.3cm and 1.5cm of 1] {$3$};

    (1) edge node {} (2)
    (2) edge node {} (3)
    (3) edge node {} (1);
    \node[main node] (1) {$1$};
    \node[main node] (2) [right = 2cm  of 1]  {$2$};
    \node[main node] (3) [below = 2cm  of 1] {$3$};
    \node[main node] (4) [right = 2cm  of 3] {$4$};

    (1) edge node {} (2)
    (1) edge node {} (4)
    (3) edge node {} (2)
    (3) edge node {} (4)

enter image description here

  • I am a member of that mafia :)
    – user11232
    Feb 7, 2014 at 15:24
  • Thank you very much! You're a rescuer, not an helper! ;)
    – Driu
    Feb 7, 2014 at 15:33
  • Appreciate your honesty, Don Kumar. There is kind of a double moral on this site sometimes: questions are closed because they are of the type "do this for me", but if it sounds fun, other questions are answered nevertheless.
    – Ingo
    Feb 12, 2014 at 11:01
  • 4
    @Ingo Thanks. As I am a teacher by profession, I always feel that beginners need to be given a hand. :)
    – user11232
    Feb 12, 2014 at 22:52

You're not going to get really popular here with questions like "I don't have time for this, do it for me". However I've been a newbie and I've got a lot of help from here. I'm still a newbie =).

Triangle with numbers:


\begin{tikzpicture}[main_node/.style={circle,fill=blue!20,draw,minimum size=1em,inner sep=3pt]}]

    \node[main_node] (1) at (0,0) {1};
    \node[main_node] (2) at (-1, -1.5)  {2};
    \node[main_node] (3) at (1, -1.5) {3};

    \draw (1) -- (2) -- (3) -- (1);

The syntax is really simple and self-explanatory: Put these node here, there and there. The the parentheses after the \node command is the id of that node. Then, to draw the connections you can use those ids: connect 1 with 2 with a straight line, 2 with 3 and 3 with 1.

If you are looking something more like the image you put down there, this will do:


\begin{tikzpicture}[main_node/.style={circle,fill=blue!60,minimum size=1em,inner sep=3pt]}]

    \node[main_node] (1) at (0,0) {};
    \node[main_node] (2) at (-1, -1.5)  {};
    \node[main_node] (3) at (1, -1.5) {};

    \draw (1) -- (2) -- (3) -- (1);

Note that:

  • No text is given in the braces {}
  • blue!60 means "a 60% of blue". That's why your blue!20 was lighter.
  • I didn't draw the border. Maybe it could be improved by drawing the border in the same color as the node.

Having this, the other figure is easy.


You could try the new graph drawing library (which requires lualatex):

\tikz\path [graphs/.cd, nodes={shape=circle, fill=blue!40, draw=none, outer sep=0pt}, empty nodes]
  graph [tree layout] { A1 -- {B1 -- C1} -- A1 }
  graph { A2 -- B2; C2 -- D2; A2 -- D2;  B2 -- C2 };

enter image description here

  • This library is simply amazing. It simplifies the workflow a lot!
    – Ingo
    Feb 13, 2014 at 10:10
  • I'm struggling to get this working in a document, I have lualatex installed (sudo apt-get install texlive-luatex) How would this code be used without creating a separate standalone document? A tikZ floating section or something? I'm unfamiliar, but it looks nice to use. Thanks
    – baxx
    Apr 13, 2015 at 1:24

The answers are never complete without PSTricks.

&[]&&[]&&[]\\ []&&[]&[]&&[]

enter image description here


linecolor=. sets the color to black. The same notation used by Mathematica to reset the variables.

  • 1
    Very True: "answers are never complete without PSTricks" Feb 7, 2014 at 18:16
  • Any idea why :fillcolor=blue!40 does not fill color in nodes using xelatex engine Feb 7, 2014 at 18:21
  • @texenthusiast: I need to pass this issue to PSTricks mailing list. Feb 7, 2014 at 18:24

With tkz-graph


  \SetVertexSimple[MinSize    = 16pt, LineColor = blue!60, FillColor = blue!60]


enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .