5

Here is my LaTeX code:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}

\node[circle,color=yellow,fill=red,font=\Huge] at (0, 0) {foo};
\node[circle,fill=red,color=yellow,font=\Huge] at (3, 0) {foo};

\end{tikzpicture}
\end{document}

Here is the output:

enter image description here

The second circle was supposed to show yellow text on red background. Why is completely yellow?

Lone Learner
  • 3,226
  • 24
  • 44
  • 4
    color sets all colors, most notable text, draw and fill. And pgfkeys uses the principle of overwriting previous keys. – TeXnician Feb 08 '18 at 16:00
  • 1
    Take a look at https://tex.stackexchange.com/questions/147582/set-textcolor-in-tikzstyle/147626#147626 and you'll see that the color of text in nodes is fixed with text option – Ignasi Feb 08 '18 at 16:26

1 Answers1

6

Your code uses the color key. This is a shorthand (meta key) for most colors you could change, most notably text, draw and fill. You could even omit the color= part as it will be used by default.

Apart from the meaning of the key the order is very important as pgfkeys (which is used by TikZ) processes the keys in order and does not preserve values meaning that once you specify the key again (or in a meta key like color) it will be overwritten.

Hence the answer to your question: It is completely yellow, because you set text and fill color to yellow after you specified another color.

TeXnician
  • 33,589