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.

I have a certain TikZ style that I would like to use over and over again (so I'd like to use it as a scope). Namely, I want the color of the curves to be red, with white borders (to give a "crossing over" effect when the curves go over each other), and I want the color of the text to be red too. Currently I am using the "double" effect to accomplish this, like so:

\tikzset{curveinscope/.style={every path/.style={draw=white, double distance=1pt, line width=2pt, double=red, color=red}}}

However this clashes with the "double" effect: setting "color=red" to make the text color red sets the drawing color of the first line in the "double" to also be red, which messes up the effect (it needs to be white).

How can I fix this?

share|improve this question
add comment

2 Answers 2

up vote 13 down vote accepted

You should set the color using text=red instead of color=red:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\tikzset{curveinscope/.style={every path/.style={draw=white, double distance=1pt, line width=2pt, double=red, text=red}}}

\begin{scope}[curveinscope]
\node at (1,0) {X};
\draw (0,0) -- (2,2);
\draw (2,1) -- (0,1);
\end{scope}

\end{tikzpicture}
\end{document}

share|improve this answer
    
I knew there was a text-specific colour option but tried text color first and got an error. Next time, I'll check the manual before posting. –  Loop Space Jun 15 '11 at 11:30
    
@Andrew: Hehe, I did exactly the same thing (trying text color first, that is). Maybe there should be an alias for the option. –  Jake Jun 15 '11 at 11:31
    
I have a memory of a text color option. Maybe it was an older version of PGF that was dropped in favour of the more concise text=colour. –  Loop Space Jun 15 '11 at 11:47
    
Thanks a lot! I couldn't find that text=red color option in the manual. This is definitely a simple solution :-) –  Bruce Bartlett Jun 15 '11 at 14:05
    
@Bruce: Section 16.4.1 in the manual for PGF2.10. –  Loop Space Jun 15 '11 at 16:38
add comment

Separate your path-specific options from your node-specific ones. Put the node-specific ones in an every node/.style:

\documentclass{standalone}
\usepackage{tikz}
\tikzset{curve in scope/.style={
    every path/.style={
      draw=white,
      double distance=1pt,
      line width=2pt,
      double=red,
    },
    every node/.style={
      color=red
    }
  },
  curve in scope with bad colours/.style={
    every path/.style={
      draw=white,
      double distance=1pt,
      line width=2pt,
      double=red,
      color=red
    }
  }
}
\begin{document}
\begin{tikzpicture}
\begin{scope}[curve in scope]
\path (0,0) -- node[auto] {hello world} (3,0);
\end{scope}
\begin{scope}[curve in scope with bad colours,yshift=-1cm]
\path (0,0) -- node[auto] {hello world} (3,0);
\end{scope}
\end{tikzpicture}
\end{document}

Result:

colours on paths and nodes

share|improve this answer
    
Thanks Andrew, this teaches me some good practice here. I didn't know about the every node option. –  Bruce Bartlett Jun 15 '11 at 14:03
1  
@Bruce: Yes, whilst Jake's is the more concise of the solutions, I think that the principle of separation is worth pointing out too. –  Loop Space Jun 15 '11 at 16:37
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.