3

I am using tikz to draw graphs like this :

The result is fine if I use only one(!) of them :

      \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,thick,main node/.style={circle,fill=white!20,draw,font=\sffamily\Large\bfseries}]

  \node[main node] (1) {v1};
  \node[main node] (2) [below left of=1] {v2};
  \node[main node] (3) [below right of=2] {v3};
  \node[main node] (4) [below right of=1] {v4};

  \path[every node/.style={font=\sffamily\small}]
    (1) edge node [left] {} (2)
    (2) edge node [right] {} (3)
    (3) edge node [right] {} (4)
    (4) edge node [left] {}(1);

\end{tikzpicture}

Result:

Bild 1

enter image description here

And the other one:

     \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,thick,main node/.style={circle,fill=white!20,draw,font=\sffamily\Large\bfseries}]

  \node[main node] (1) {v1};
  \node[main node] (2) [right of=1] {v2};
  \node[main node] (3) [right of=2] {v3};

  \path[every node/.style={font=\sffamily\small}]
    (1) edge node [left] {} (2)
    (2) edge node [right] {} (3);


\end{tikzpicture}

result:

enter image description here

But if the code above is used together in the same code I get this weird result :

Bild 3

enter image description here

So the drawing are mixed into each other. How can I separate the drawing?

Thanks!!!

Herr K.
  • 17,946
  • 4
  • 61
  • 118
  • by the way this "you can't post images because you need at leat 10 reputations..." rule is more than senseless.... -_- –  Nov 25 '13 at 18:25
  • 3
    At its core it is to avoid spam. I will put the picture up for you. EDIT: Wow that website you used to post your picture was virus city lol. –  Nov 25 '13 at 18:30
  • Welcome to TeX.SX! Your post was migrated here from another Stack Exchange site. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. Finally what do you mean by using in the same code? – percusse Nov 26 '13 at 05:57

1 Answers1

3

If by "used together in the same code" you meant combining the first two graphs in the same tikzpicture environment, then the problem stems from the fact that you didn't specify a position for the node v1 in the second graph (and as a result, it's put at the default coordinate, which also happens to be where v1 in the first picture is).

Explicitly give a coordinate for v1 in the second graph. For example, absolute placement,

\node[main node] (1) at (<coordinate>) {v1};

or relative placement

\node[main node, right=of 4] (1) {v1};

Full code

\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning}

\begin{document}

\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,thick,main node/.style={circle,fill=white!20,draw,font=\sffamily\Large\bfseries}]

  \node[main node] (1) {v1};
  \node[main node] (2) [below left=of 1] {v2};
  \node[main node] (3) [below right=of 2] {v3};
  \node[main node] (4) [below right=of 1] {v4};

  \path[every node/.style={font=\sffamily\small}]
  (1) edge node [left] {} (2)
  (2) edge node [right] {} (3)
  (3) edge node [right] {} (4)
  (4) edge node [left] {}(1);

  \node[main node] (1) [right=of 4] {v1};
  \node[main node] (2) [right=of 1] {v2};
  \node[main node] (3) [right=of 2] {v3};

  \path[every node/.style={font=\sffamily\small}]
  (1) edge node [left] {} (2)
  (2) edge node [right] {} (3);
\end{tikzpicture}
\end{document}

Output

enter image description here


Note also that I changed your right of=... syntax to right=of .... See Difference between "right of=" and "right=of" in PGF/TikZ for more details.

Herr K.
  • 17,946
  • 4
  • 61
  • 118