2

I am trying to make a multi graph, but the edges all overlap one another. This question has already been asked but I have not been able to find a solution that will work for the format I am using.

I have the following code so far:

\begin{tikzpicture}[scale=2,vertex/.style={circle, fill=black!30, draw, minimum size=.3cm, inner sep=0pt}, 
    arc1/.style={draw=red,line width=1.5pt}, 
    arc2/.style={draw=blue,line width=1.5pt},
    arc3/.style={draw=orange,line width=1.5pt},
    arc4/.style={draw=purple,line width=1.5pt},
    arc5/.style={draw=green,line width=1.5pt}]
    \foreach [count=\i] \coord in {(0,0), (1,1), (-1,1), (1,2), (-1,2)}{
        \node[vertex] (p\i) at \coord {\i};
    }

    \foreach [count=\r] \row in {{0,1,0,0,0}, {1,0,0,1,0}, {0,0,0,0,0}, {0,1,0,0,0}, {0,0,0,0,0}}{
        \foreach [count=\c] \cell in \row{
            \ifnum\cell=1%
            \draw[arc1] (p\r) edge (p\c);
            \fi
        }
    }
    \foreach [count=\r] \row in {{0,0,1,0,0}, {0,0,0,0,0}, {1,0,0,0,1}, {0,0,0,0,0}, {0,0,1,0,0}}{
        \foreach [count=\c] \cell in \row{
            \ifnum\cell=1%
            \draw[arc2] (p\r) edge (p\c);
            \fi
        }
    }
    \foreach [count=\r] \row in {{0,1,0,0,0}, {1,0,1,0,0}, {0,0,1,0,1}, {0,0,0,0,0}, {0,0,1,0,0}}{
        \foreach [count=\c] \cell in \row{
            \ifnum\cell=1%
            \draw[arc3] (p\r) edge (p\c);
            \fi
        }
    }
    \foreach [count=\r] \row in {{0,0,1,0,0}, {0,0,1,1,0}, {1,1,0,0,0}, {0,1,0,0,0}, {0,0,0,0,0}}{
        \foreach [count=\c] \cell in \row{
            \ifnum\cell=1%
            \draw[arc4] (p\r) edge (p\c);
            \fi
        }
    }
    \foreach [count=\r] \row in {{0,1,0,0,0}, {1,0,1,0,0}, {0,1,0,0,1}, {0,0,0,0,1}, {0,0,1,1,0}}{
        \foreach [count=\c] \cell in \row{
            \ifnum\cell=1%
            \draw[arc5] (p\r) edge (p\c);
            \fi
        }
    }
    \end{tikzpicture}

I just need each coloured edge to be visible. I am sure it is a simple change to the line arc1/.style={draw=red,line width=1.5pt}, but everything that I have tried will not work. Any help will be much appreciated.

red and green :)

1

You can bend the arcs, each color with a different curvature, by adding

bend left=...some number...

to the arc/.style definitions. Note that you cannot use straight lines (curvature=0), since you have arcs of the same color from A to B and from B to A, of which probably both should remain visible.

enter image description here

\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=2,vertex/.style={circle, fill=black!30, draw, minimum size=.3cm, inner sep=0pt}, 
    arc1/.style={draw=red,line width=1.5pt,bend left=10}, % <<<<<<<<<<<
    arc2/.style={draw=blue,line width=1.5pt,bend left=15}, % <<<<<<<<<<<
    arc3/.style={draw=orange,line width=1.5pt,bend left=20}, % <<<<<<<<<<<
    arc4/.style={draw=purple,line width=1.5pt,bend left=25}, % <<<<<<<<<<<
    arc5/.style={draw=green,line width=1.5pt,bend left=5}] % <<<<<<<<<<<
    \foreach [count=\i] \coord in {(0,0), (1,1), (-1,1), (1,2), (-1,2)}{
        \node[vertex] (p\i) at \coord {\i};
    }

    \foreach [count=\r] \row in {{0,1,0,0,0}, {1,0,0,1,0}, {0,0,0,0,0}, {0,1,0,0,0}, {0,0,0,0,0}}{
        \foreach [count=\c] \cell in \row{
            \ifnum\cell=1%
            \draw[arc1] (p\r) edge (p\c);
            \fi
        }
    }
    \foreach [count=\r] \row in {{0,0,1,0,0}, {0,0,0,0,0}, {1,0,0,0,1}, {0,0,0,0,0}, {0,0,1,0,0}}{
        \foreach [count=\c] \cell in \row{
            \ifnum\cell=1%
            \draw[arc2] (p\r) edge (p\c);
            \fi
        }
    }
    \foreach [count=\r] \row in {{0,1,0,0,0}, {1,0,1,0,0}, {0,0,1,0,1}, {0,0,0,0,0}, {0,0,1,0,0}}{
        \foreach [count=\c] \cell in \row{
            \ifnum\cell=1%
            \draw[arc3] (p\r) edge (p\c);
            \fi
        }
    }
    \foreach [count=\r] \row in {{0,0,1,0,0}, {0,0,1,1,0}, {1,1,0,0,0}, {0,1,0,0,0}, {0,0,0,0,0}}{
        \foreach [count=\c] \cell in \row{
            \ifnum\cell=1%
            \draw[arc4] (p\r) edge (p\c);
            \fi
        }
    }
    \foreach [count=\r] \row in {{0,1,0,0,0}, {1,0,1,0,0}, {0,1,0,0,1}, {0,0,0,0,1}, {0,0,1,1,0}}{
        \foreach [count=\c] \cell in \row{
            \ifnum\cell=1%
            \draw[arc5] (p\r) edge (p\c);
            \fi
        }
    }
    \end{tikzpicture}
\end{document}

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.