グラフ内の特定のエッジと頂点を色分けする

グラフ内の特定のエッジと頂点を色分けする

一部のエッジと頂点のみを別の色にするにはどうすればいいですか?

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

ここに画像の説明を入力してください

関連情報