tikz多重图中的平行线

tikz多重图中的平行线

我正在尝试制作多图,但所有边都相互重叠。这个问题已经有人问过了,但我还没有找到适合我使用的格式的解决方案。

到目前为止我有以下代码:

\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}

我只需要让每个彩色边缘都清晰可见。我确信这只是对线条的简单更改arc1/.style={draw=red,line width=1.5pt},,但我尝试过的所有方法都不起作用。任何帮助都将不胜感激。

红色和绿色:)

答案1

您可以通过添加不同的颜色来弯曲弧线,每种颜色都有不同的曲率

bend left=...some number...

定义arc/.style。请注意,您不能使用直线(曲率=0),因为您有从 A 到 B 和从 B 到 A 的相同颜色的弧,其中两条弧可能都应该保持可见。

在此处输入图片描述

\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}

相关内容