4

I'm trying to get Parallel edges between nodes. I recognize that very similar questions have been asked before, however;

  1. Those solutions don't seem to have worked on my problem, though my search was not exhaustive. Most solutions seem to use \draw, and I don't yet have the skill to reconcile \path approach with \draw. Further, I couldn't find mention in the 3.0.0 documentation.

  2. I'd like to keep this style consistent with other graphs that I have done for a report, as I already have a few examples working. If someone knows how to remove the arrow from the loop that would be very helpful also. As you can see I have tried using "stealth", but haven't had any luck.

My code so far:

\documentclass[14pt,oneside,a4paper]{report}
\usepackage{tikz}
 \usetikzlibrary{arrows,decorations.pathmorphing,backgrounds,positioning,fit,petri}
\begin{document}
\begin{figure}

\sbox{\tempbox}{%
\begin{tikzpicture}[-,>=stealth',shorten >=1pt,auto,node distance=2cm,
  thick,main node/.style={circle,fill=black!20,draw}]

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

  \path[every node/.style={font=\sffamily\small}]
    (1) edge[loop left] node  {$e_{1}$} (1)
    (1) edge node [left] {} (2)
    (1) edge node [left] {} (3)
    (2) edge node [right] {} (3);
    \path [draw, line width=3] (2) |-(3);
\end{tikzpicture}
} 

\begin{subfigure}{.5\textwidth}
\centering
\usebox{\tempbox}
\caption{A non-simple Graph}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
\centering
\vbox to\ht\tempbox{
    \vfill
\begin{math}
A_{G} = \left(
\begin{array}{ccc}
1 & 1 & 1 \\
1 & 0 & 2 \\
1 & 2 & 0 

\end{array}
\right)
\end{math}
\vfill
}
\caption{Matrix Corresponding to the Graph }
\end{subfigure}%
\caption{A graph's diagram and it's adjacency matrix representation.}
\end{figure}
\end{document}

The graphics output

The top Graph is of the style I'm aiming for. The Graph below it is what the code posted creates. The sharp-angled edge is the one which i'm wishing to modify to be smoother. I've tried using:

(2) edge node [bend left = 15] {} (3);

However that didn't work. NB: I really don't know what I'm doing. I included the Matrix as I'm working in a figure environment, if that is meaningful.

3
  • 1
    Please, make your document complete, than can be copied and compiled. Also try to remove errors in use of subfigure. – Zarko Feb 3 '16 at 12:56
  • Why did you add a node in the edge if it's supposed to be empty anyways? – Alenanno Feb 3 '16 at 13:11
  • Maybe for future use? I was unsure about their purpose, so I didn't touch them in my answer. Instead nodes I would rather use quotas library ... – Zarko Feb 3 '16 at 13:15
3

Edit: In the first attempt I miss understand question, so I add arrows instead to remove it from loop. Hot to do this is described in TikZ manual on page 749 (version 3.0.1a)

Something like this?

enter image description here

\documentclass{article}
\usepackage{subcaption}

\usepackage{tikz}
    \usetikzlibrary{arrows,positioning}

\begin{document}
\begin{figure}

\newsavebox\tempbox
\sbox{\tempbox}{%
\begin{tikzpicture}[
    thick, shorten >=1pt, 
    auto,
    node distance=2cm,
  main node/.style={circle, draw, fill=black!20}
                    ]
\node[main node] (3) {$v_3$};
\node[main node] (1) [below left =of 3] {$v_1$};% <--- se proper use of positioning 
\node[main node] (2) [below right=of 3] {$v_2$};

  \path[every loop/.style={}]
    (1) edge[loop left,"$e_{1}$"] (1)% <-- for edge labels I use quotes library

    (1) edge (2)% <-- nodes are removed since they are not used
    (1) edge (3)
    (2) edge (3)
    (3) edge [red, bend left] (2); % <-- edge is now smooth
\end{tikzpicture}
}

\begin{subfigure}{.5\textwidth}
\centering
\usebox{\tempbox}
\caption{A non-simple Graph}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
\centering
\vbox to\ht\tempbox{
    \vfill
\begin{math}
A_{G} = \left(
\begin{array}{ccc}
1 & 1 & 1 \\
1 & 0 & 2 \\
1 & 2 & 0
\end{array}
\right)
\end{math}
\vfill
}
\caption{Matrix Corresponding to the Graph }
\end{subfigure}%
\caption{A graph's diagram and it's adjacency matrix representation.}
\end{figure}
    \end{document}    

To code I add comments to see, what I change in your MWE

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.