4

Please, consider the following simple example:

\documentclass[tikz, border=3mm, preview]{standalone}

\begin{document}
\begin{tikzpicture}[
every node/.append style = {text=blue}
                    ]
\node {root}
    child {node {left}}
    child {node {right}
        child {node {\textcolor{red}{L} child}}
        child {node {R child}}
            };
\end{tikzpicture}
\end{document}

which gives:

enter image description here

Why text in L child node hasn't red L and blue child? Interestingly, if I change color orders:

child {node {L \textcolor{red}{child}}

then result is as expected: blue L and redchild:

enter image description here

Zarko
  • 296,517
  • I think this may be related to a question I asked a little while ago about Forest. Let me see if I can find it ... – cfr Nov 08 '16 at 00:50
  • http://tex.stackexchange.com/questions/300423/how-to-apply-colour-options-to-the-contents-of-tikz-nodes-when-the-content-inclu I think your question is the same, but I'm not certain. – cfr Nov 08 '16 at 00:53
  • @cfr, yes, my question is somehow related to yours in tex.stackexchange.com/questions/300423/… . I test solution given in * Symbol 1* comment it solve my problem. However, the problem which I "rediscover" is, as pointed * David Carlisle* is the bug. Since, my question is not related to forest, maybe it is worth that you make an answer to it? – Zarko Nov 08 '16 at 01:05
  • Tree structure is unnecessary; \tikz\node[text=blue]{{\color{red}L} root}; will show the problem. Even more irony: \tikz\node[text=blue]{{\color{.}L} root}; – Symbol 1 Nov 08 '16 at 03:24
  • You are right. This is not specific to tree but problem of nodes as such. Accidentally I discover this at drawing of tree. I think that my question is solved by comments. – Zarko Nov 08 '16 at 03:29

1 Answers1

5

Before the question is voted to closed, I have something more than a comment:

Color setting in PGF/TikZ is done is its own way. For example in node[red]{foo} and node[text=red]{foo} the color is ultimately set by \pgfsetcolor{red} [1]. This comment is documented as follows

\pgfsetcolor{⟨color⟩} Sets both the stroke and fill color. The difference to the normal \color command is that the effect lasts till the end of the current {pgfscope}, not only till the end of the current TEX group.

To my best understanding, this is saying that PGF's \pgfsetcolor and the regular \color are incompatible. In your case, you should either stick to \color by setting node[font=\color{blue}] or stick to \pgfsetcolor by saying node[text=blue]{\pgfsetcolor{red}L \pgfsetcolor{.}root}.

[1] to be precise, it is \tikzoption{text}{\def\tikz@textcolor{#1}} and then \pgfutil@colorlet{.}{\tikz@textcolor} and then \pgfsetcolor{.}.

Symbol 1
  • 36,855