Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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 pattern of graphs: a triangle and a complete bipartite graph (see picture 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 simply awful! This is my try.

\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 give me any help to improve this result?

Thank you.

Graph pattern

share|improve this question
@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. –  Claudio Fiandrino Feb 7 at 15:04
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 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 at 17:50
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 at 18:27

5 Answers 5

up vote 21 down vote accepted

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

share|improve this answer
I am a member of that mafia :) –  Harish Kumar Feb 7 at 15:24
Thank you very much! You're a rescuer, not an helper! ;) –  Driu Feb 7 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 at 11:01
@Ingo Thanks. As I am a teacher by profession, I always feel that beginners need to be given a hand. :) –  Harish Kumar Feb 12 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.

share|improve this answer

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

share|improve this answer
This library is simply amazing. It simplifies the workflow a lot! –  Ingo Feb 13 at 10:10

With tkz-graph


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


enter image description here

share|improve this answer

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.

share|improve this answer
Very True: "answers are never complete without PSTricks" –  texenthusiast Feb 7 at 18:16
Any idea why :fillcolor=blue!40 does not fill color in nodes using xelatex engine –  texenthusiast Feb 7 at 18:21
@texenthusiast: I need to pass this issue to PSTricks mailing list. –  cyanide-based food Feb 7 at 18:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.