如何仅使某些边和顶点具有不同的颜色?
\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}