Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Consider the following code:

\documentclass{article}
\usepackage{tikz}
\begin{document}
  \begin{tikzpicture}
    \begin{scope}[fill=red, draw=green,text=blue]
      \node[fill=red, draw=green] at (0,0) {A};
      \node[text=black] at (2,0) {B};
    \end{scope}
  \end{tikzpicture}
\end{document}

My question is: Why do only the text option to the \scope environment work? (That is: I would like the B-node to have a red background and a green border, but as seen from the included image, nothing happens) enter image description here

share|improve this question
add comment

2 Answers 2

up vote 8 down vote accepted

This is a common misunderstanding of how a node actually behaves. A node is not a \path in itself, per definition.

A node has its own name-space in terms of special keys which apply to it.

The reason is \node gets expanded to \path node and whatever is in the scope environment is only appended to paths. This means your code is equivalent to:

\begin{tikzpicture}
  \begin{scope}[fill=red, draw=green,text=blue]
    \node[fill=red, draw=green] at (0,0) {A};
    \path (2,0) node[text=black] {B};
  \end{scope}
\end{tikzpicture}

which much clearer what is happening. Hence, you could do this:

  \begin{scope}[all/.style={fill=red, draw=green,text=blue},all,
       every node/.append style={all}]

to achieve what you want, all is then used every where, even on nodes.

share|improve this answer
    
Thank you for the nice explanation.. I think this point is not made very clear in the TikZ-documentation. As far as I can see, it is not mentioned in chapter 12.3, "Using scopes to structure a picture" –  Håkon Hægland Mar 10 '13 at 16:02
add comment

The nodes do not inherit the path options. To make it work you can use

  \begin{tikzpicture}
    \begin{scope}[every node/.style={fill=red, draw=green,text=blue}]
      \node at (0,0) {A};
      \node[text=black] at (2,0) {B};
    \end{scope}
  \end{tikzpicture}

then the resulting picture is

enter image description here

share|improve this answer
    
Thank you.. I was not aware of the difference between nodes and paths regarding scope options.. –  Håkon Hægland Mar 10 '13 at 16:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.