I am trying to draw an undirected graph with some edges colored with two colors side-by-side. I really like this solution suggested by Symbol 1, but I cannot get it to work for straight edges.
Any help would be greatly appreciated!
MWE:
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{arrows}
\tikzset{
semithick,
node distance = 2cm,
dot/.style={circle,fill,inner sep=2pt}
}
\tikzset{
side by side/.style 2 args={
line width=2pt,
#1,
postaction={
clip,postaction={draw,#2}
}
}
}
\tikzstyle{every state}=[draw = black,thick,fill = white,minimum size = 4mm]
\tikzstyle{selected edge} = [draw,line width=2pt,-,red!50]
\begin{document}
\begin{tikzpicture}
\node[dot] (0) {};
\node[dot] [right of=0] (1) {};
\node[dot] [below right of=1, yshift=15] (2) {};
\node[dot] [below of=0] (3) {};
\node[dot] [right of=3] (4) {};
\path (0) edge[side by side={red!50}{blue!50},bend left] (1);
\path (0) edge[side by side={red!50}{blue!50},bend right] (3);
\path (1) edge (2);
\path (1) edge[selected edge] (4);
\path (1) edge (4);
\path (3) edge[selected edge] (1);
\path (3) edge (1);
\path (3) edge[side by side={red!50}{blue!50},bend right] (4);
\path (4) edge[side by side={red!50}{blue!50},bend right] (2);
\end{tikzpicture}
\end{document}


tikzsetandtikzstylehere. The latter is deprecated nowadays. Try and use onlytikzset. – SebGlav Feb 14 '21 at 09:58bend right=angle. where angle is 10 or lower. If it gets too small, the second color vanishes. This is not a solution, but maybe you can live with a weakly bent edge (unless there is a better solution). – gernot Feb 14 '21 at 12:11