例如我有这个:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows, automata, positioning}
\begin{document}
\begin{tikzpicture} [->, >=stealth', shorten >= 1pt, auto, node distance = 4cm, thick, state/.style = {circle, draw, font = \sffamily\Large\bfseries}]
\node[state] (1) {1};
\node[state] (2) [right of = 1] {2};
\path[every node/.style={font=\sffamily\small}, label={[align=center]below:unit\\cell}]
(1) edge node [above, color = red] {A B C} (2);
\end{tikzpicture}
\end{document}
这会将 1 到 2 之间的边渲染为红色,其中“AB C”。但我想将 A 渲染为红色,将 B 渲染为蓝色,将 C 渲染为绿色。
答案1
你可以使用通常的方式在节点内切换颜色,即使用\textcolor{<colour>}{<text>}
或\color{<colour>} <text>
。例如:
\documentclass[tikz,border=10pt]{standalone}
\begin{document}
\begin{tikzpicture}
\path[every node/.style={font = \sffamily\small}, label ={[align = center]below:unit\\cell}]
(0,1) edge node [left, color = red] {A \textcolor{blue}{B} \textcolor{green}{C}} (0,2);
\end{tikzpicture}
\end{document}