1

The answer referenced is https://tex.stackexchange.com/a/45735/180050 and is essential for this question.

In the given answer, it shows how you can easily make directed edges between specified nodes.

I was wondering how I could do the same but with undirected edges (lines with no arrows).

Edit:

I appreciate the linked duplicate, and I used Jake's comment to the main post of adding [-] to edge for typical edges. However, this does not work for self-loops, and fixing that is not in the linked solution.

  • 4
    Remove -> and shorten>=1pt from the option list of the tikzpicture environment. For the loops you have to add every loop/.style={}. – esdd Apr 24 '19 at 06:27
  • @esdd I used Jake's comment to the main post here to solve the typical edge: https://tex.stackexchange.com/questions/52085/drawing-simple-edge-no-arrow – Gigi Bayte 2 Apr 25 '19 at 01:33
  • Is it possible to use something like edge[-] for a self-loop instead of changing the global settings? Like just remove the arrow from one loop with the default being to have the arrows? – Gigi Bayte 2 Apr 25 '19 at 01:34
  • I saw your post in the reopening queue and am wondering if you are simply looking for every loop/.append style={-} in the options of the tikzpicture. Notice that I did not (vote to) close your question, but I can see why people could want to close it. It would be much better if you added a simple example such that it is clear what you want (unless the above solved it already). Once this is done I will be happy to help you reopening the question. –  Apr 25 '19 at 02:14

1 Answers1

1

The global switching off of arrows can be achieved as in esdd's comment or bay saying very loop/.append style={-}. Local switching off works essentially the same, I added a style no arrow for that.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,
                    thick,main node/.style={circle,draw,font=\sffamily\Large\bfseries},
                    no arrow/.style={-,every loop/.append style={-}}
                    ]

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

  \path[every node/.style={font=\sffamily\small}]
    (1) edge node [left] {0.6} (4)
        edge [bend right] node[left] {0.3} (2)
        edge [no arrow,loop above] node {0.1} (1)
    (2) edge node [right] {0.4} (1)
        edge node {0.3} (4)
        edge [loop left] node {0.4} (2)
        edge [bend right] node[left] {0.1} (3)
    (3) edge node [right] {0.8} (2)
        edge [bend right] node[right] {0.2} (4)
    (4) edge node [left] {0.2} (3)
        edge [loop right] node {0.6} (4)
        edge [bend right] node[right] {0.2} (1);
\end{tikzpicture}
\end{document}

enter image description here

  • Thanks for showing me how I can universally do it! Is there a way to have it such that the default adds an arrow and you can locally choose to make it not have an arrow? – Gigi Bayte 2 Apr 25 '19 at 20:41
  • Like how you can change edge node [left] {0.6} (4) to edge [-] node [left] {0.6} (4) to make a nonloop edge not have an arrow? – Gigi Bayte 2 Apr 25 '19 at 20:42
  • @GigiBayte2 Yes, it works the same way. I added a style no arrow that makes this more convenient. (One may argue that just adding -> is not such a great idea, but I take you want to keep this.) –  Apr 25 '19 at 20:49
  • Hi! Would it be possible to add an allowable style for each node similar to how you did the "no arrow" style to fill the node a certain color? – Gigi Bayte 2 May 01 '19 at 05:23
  • @GigiBayte2 \tikzset{every node/.append style={fill=blue}}? –  May 01 '19 at 05:25
  • Ah... I just realized that I can do fill=blue in the creation of the nodes like \node[fill=blue, main node]... – Gigi Bayte 2 May 01 '19 at 09:07