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.

In TikZ we can use every node/.style=... and every label/.style=... but is there a way to say something like every non label/.style=... so that I can define styles for non-label and label nodes without interference?

share|improve this question
    
I used the following and it seems to work, although there can be other interferences. \tikzset{every node/.style ={draw,red},every label/.style={draw=none,blue}} \begin{tikzpicture} \node[label={0:A}] {B}; \end{tikzpicture} –  percusse Mar 23 '12 at 12:18
    
@percusse Well I have every node/.style={circular drop shadow} and this is afecting my labels too, and I don't know how to disable the shadow for labels ... –  Mário Mar 23 '12 at 12:33
1  
@Mário: I guess you only want to apply circular drop shadow to circle nodes, right? In that case, you could pass that option to every circle node instead of every node to keep it from applying to labels. Unless they're circular, of course. Hm, I'd really like to see a clever approach for the every non label style problem. Maybe Ryan Reich can come up with something. –  Jake Mar 23 '12 at 12:45
    
@Jake: That would perhaps work if my nodes where defined has node[circle ... but I am defining every node/.style={ellipse, circular drop shadow, ...}, every label/.style={...}. Then I have \node[label=thelabel]{...} and the node is draw as an ellipse with a shadow, but its label is also an ellipse with a shadow ... –  Mário Mar 23 '12 at 13:01
add comment

4 Answers

Tackling the problem a little bit different (and comming from Reduce white space above TikZ label), I’d re-define labels and pins so that they don’t actually have a every node style to use by setting this style empty:

\patchcmd\tikz@@parse@label{\bgroup}{\bgroup[every node/.style=]}{}{}
\patchcmd\tikz@@parse@pin{\bgroup}{\bgroup[every node/.style=]}{}{}

The real every node style is now every Node which is included in every node, every label and every pin manually.
Furthermore, with .style I also removed the initial draw=none, fill=none of every label and every pin which now need to be given explicitly.

If this should still be present in those styles, instead of .style use .prefix style or .append style (whatever is needed).

The style every node and pin is the same as every non label.

Code

\documentclass[tikz]{standalone}
\usepackage{etoolbox}
\makeatletter
\patchcmd\tikz@@parse@label{\bgroup}{\bgroup[every node/.style=]}{}{}
\patchcmd\tikz@@parse@pin{\bgroup}{\bgroup[every node/.style=]}{}{}
\makeatother
\tikzset{
  every node/.style={every Node/.try, every node and label/.try, every node and pin/.try},
  % every label is initially "draw=none, fill=none"
  every label/.style={every Node/.try, every node and label/.try, every label and pin/.try},
  % every pin is initially "draw=none, fill=none"
  every pin/.style={every Node/.try, every node and pin/.try, every label and pin/.try},
  Nodes/.style={every Node/.append style={#1}}}
\begin{document}
\tikzset{Nodes=draw}
\tikz\node[label=bar, pin=below:pin] {foo};
\tikz[nodes=circle]\node[label=bar, pin=below:pin] {foo};
\tikz[Nodes=circle]\node[label=bar, pin=below:pin] {foo};
\end{document}

Output

enter image description hereenter image description hereenter image description here

share|improve this answer
add comment

No tricky no hackish solution because I think it's bad problem. It's a bad use of every node.

This situation appears in some tutorials of the pgfmanual. First Andrew makes this remark : The key every label is called after the every node and It's necessary to complete with a text from the pgfmanual :

/tikz/label=[⟨options⟩]⟨angle⟩:⟨text⟩ (no default) When this option is given to a node operation, it causes another node to be added to the path after the current node has been finished. This extra node will have the text ⟨text⟩.

In other terms, the label is another node, so it's normal that you get some interferences.

What you need to do ? You can work with a ticky or hackish method or you can avoid the problem with a more natural code.

I tink the better way is to define a style not for every node but for a specific node

\documentclass[11pt]{scrartcl}
\usepackage{tikz}
\usetikzlibrary{shadows}
\begin{document} 

 \begin{tikzpicture} [every node/.style = {circle},
                      every special node/.style = {},
                      special node/.style={draw = blue!50,
                                           fill = blue!20,
                                           thick,
                                           every special node}]

\tikzset{every special node/.style={circular drop shadow=red!20}} 
\tikzset{every label/.style={red}}  % by default draw=none  except if every node uses "draw"

 \node[special node,label={0:A}] {B}; 
 \end{tikzpicture}
\end{document}  

enter image description here

share|improve this answer
    
It might be the case that you don't want to type a key for each node. So I agree it's a misuse however there can be cases where you need to find a convenient solution. –  percusse Mar 23 '12 at 18:56
    
@percusse Don't want to type a key for each node is not a valid argument if you get a code easier to read and process but it is a matter of taste. –  Alain Matthes Mar 23 '12 at 20:31
    
Oh come on, I only wrote 3 lines of code. :) Joking aside, I agree with you about the natural way of coding. Lastly, I'm jealous about your nice color choice but I don't want to edit once again. –  percusse Mar 24 '12 at 0:53
add comment

Another hackish solution for this particular example is to remove the shadow by emptying the preaction key. This is something I learned from this question.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shadows,shapes.geometric}
\makeatletter
\tikzset{every node/.style ={draw,shape=ellipse,circular drop shadow,blue},
every label/.style={yellow,draw=none,fill=red,shape=trapezium,fill opacity=0.5},
every label/.add code={}{\let\tikz@preactions\pgfutil@empty}
} 
\makeatother
\begin{document}
\begin{tikzpicture} 
\node[label={0:Trapezium}] {Ellipse}; 
\end{tikzpicture} 
\end{document}

enter image description here

Since the regular options can be overridden, I guess that, only pre- and post- actions remain persistent and as seen from this simple example we simply squeeze in an innocent "You know what, forget about what I said earlier about the preactions" line. Seemingly it does the job. You can add also a line for the postactions too. Still, I can imagine that there might be some persistent options left out.

share|improve this answer
add comment

Tricky. The key every node is tried on every node. The key every label is called after the every node so it is possible to undo anything that every node does in the every label, but then you'd have to remember exactly what was set and know how to undo it.

Here's one way to achieve this. It works by using the fact that labels are always subordinate to nodes, and that (so far as I'm aware), no other nodes are subordinate to them (this might be a bit funny with matrices or chains - not tested). So we want a key, say every non label, which is executed on the parent node but not on any children (labels). One way to do that is for the key every non label to clear itself upon being executed. That ensures that it doesn't propagate downwards. As we do this in a group (the node group), this clearing only affects children and not siblings (ie other proper nodes), even on the same path.

Depending on exactly what you were doing, it might be necessary to be a bit careful with how this interacts with other keys. For example, if you put a label key in an every node one then you have to ensure that the blanking key occurs first.

\documentclass{article}
%\url{http://tex.stackexchange.com/q/49096/86}
\usepackage{tikz}
\usetikzlibrary{shadows}

\tikzset{
  clear label/.style={
    append after command={
      [every non label/.style={}]
    }
  },
  every node/.style={
    every non label,
    clear label
  },
  every non label/.style={
    circular drop shadow,
  }
}

\begin{document}
\begin{tikzpicture}
\node[label=hello] {world};
\node[label=hello] at (0,-2) {world};
\path (0,-4)  node[label=hello] {world} (1,-4) node[label=hello] {world};
\end{tikzpicture}
\end{document}

Result:

non-label node style

share|improve this answer
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.