I would like to do something like:
using PGF styles in TikZ
Here is the code:
\documentclass[tikz,convert={outfile=mwe.png}]{standalone}
\begin{document}
\pgfkeys{%
/tikz/style A/.style = {text=blue},
/tikz/style B/.style = {text=red},
}
\begin{tikzpicture}
\node [thin, draw, style A] at (1,3) {Style A};
\node [thin, draw, style B] at (1,2) {Style B};
\node [thin, draw] at (1,1) {Style A + Style B};
\end{tikzpicture}
\end{document}
But the "Style A + Style B" is always the same color. How can I do to get "Style A" in style A
and "Style B" in style b
and the "+" in the node style?
Of course I could use something like {\color{blue}Style A} + {\color{red}Style B}
but it's not very flexible. I prefer to use styles instead.
Thanks in advance.
Best Answer
If you want this to work for any text then I can see two options which allow you to keep the flexability in that you only need to change the color once.
The first method uses
\colorlet
to define the colors to use and then applies the solution you proposed via\textcolor
.The second option involves nesting
tikzpictures
and this is not recommended:Code: