图中特定颜色的边和顶点

图中特定颜色的边和顶点

如何仅使某些边和顶点具有不同的颜色?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\tikzset{main node/.style={circle,fill=black,draw,minimum size=.2cm,inner sep=0pt},}
\begin{tikzpicture}
        \node[main node] (1) {};
        \node[main node] (2) [below left = .75cm and .5cm of 1] {};
        \node[main node] (3) [below right = .75cm and .5cm of 1] {};

        \path[draw,thick]
        (1) edge node {} (2)
        (2) edge node {} (3)
        (3) edge node {} (1);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

只需color = your_color向所需的每个节点和/或边添加单独的元素,例如,

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{main node/.style={circle,fill=black!20,draw,minimum size=.5cm,inner sep=0pt},}
\begin{document}
    \tikzset{main node/.style={circle,fill=black,draw,minimum size=.2cm,inner sep=0pt},}
    \begin{tikzpicture}
    \node[main node, color = red] (1) {};
    \node[main node] (2) [below left = .75cm and .5cm of 1] {};
    \node[main node] (3) [below right = .75cm and .5cm of 1] {};
    
    \path[draw,thick]
    (1) edge [color = blue] node {} (2)
    (2) edge node {} (3)
    (3) edge node {} (1);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容