2

I'm trying to make undirected edges in my graphs, but I can't figure it out. Here is a sample code:

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

  \node[main node] (1) {1};
  \node[main node] (2) [right of=1] {2};


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

Slightly simplified code:

\documentclass[tikz,border=2mm]{standalone}
        \usetikzlibrary{positioning}

    \begin{document}
        \begin{tikzpicture}[
        shorten >=1pt, auto, thick,
        node distance=3cm,
    main node/.style={circle,draw,fill=blue!20,font=\sffamily\Large\bfseries}
                            ]
      \node[main node] (1) {1};
      \node[main node] (2) [right of=1] {2};

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

Some comment: if you don't like arrowed paths, then don't define them. The first option -> at the top of the picture is selecting an arrow for all paths where applicable. Hence removing that option removes the default arrowing behavior.

For nodes you can select auto. This means that you not need to declare their position anymore and they will be placed relative to the path. And why do you define nodes on edges if you then do not use them? I put letters in them to show their position on the edges.

I also omit center environment since I do not know of it purposes. For \documentclass I select standalone. It gives me just a picture.

enter image description here

  • Either both or none of the two ends should be short of the target. – egreg Jun 14 '15 at 11:13
  • I agree, but in OP MWE is (to me not logical) showed just one. To shorten bots sides of edges OP need to add shorten <=1pt in TikZ picture option. – Zarko Jun 14 '15 at 11:30
0
\begin{center}
\begin{tikzpicture}[-,>=stealth',shorten >=1pt,auto,node distance=3cm,
  thick,main node/.style={circle,fill=blue!20,draw,font=\sffamily\Large\bfseries}]

  \node[main node] (1) {1};
  \node[main node] (2) [right of=1] {2};


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

Removing the arrow fixes it.

  • Some notes: (1) You don't need to specify node [right] {} in your path, it already exists. (2) Replace the center environment with a figure one, then add \centering right after the opening tag. (3) Your every node definition is not doing anything since there are no (visible) nodes in your path. Also, I'd rather place it inside of a tikzset. You can override it by applying another style locally, like with main node. (4) Use right =of 1 (the equal sign right before the of), see Difference between “right of=” and “right=of” in PGF/TikZ – Alenanno Jun 5 '15 at 19:01
  • 3
    @Alenanno Well, figure isn't always the correct thing. – Torbjørn T. Jun 13 '15 at 16:08
  • @TorbjørnT. I didn't say "always"? – Alenanno Jun 13 '15 at 16:22
  • @Alenanno No, but you don't know the context for this diagram, and still you recommended to replace center with figure and \centering, which could then be interpreted as 'never use the center environment for diagrams/figures in the text, always use figure'. It could well be that figure is the way to go, but we cannot say from the information that is available. – Torbjørn T. Jun 13 '15 at 16:28
  • @TorbjørnT. "which could then be interpreted as...". please don't apply your interpretation to what others have said. That's not what my comment says, so you're actually replying to something I never said. – Alenanno Jun 13 '15 at 16:57

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.