29

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?

2 Answers 2

44

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}

5
  • 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. Jun 15, 2011 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, 2011 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. Jun 15, 2011 at 11:47
  • Thanks a lot! I couldn't find that text=red color option in the manual. This is definitely a simple solution :-) Jun 15, 2011 at 14:05
  • @Bruce: Section 16.4.1 in the manual for PGF2.10. Jun 15, 2011 at 16:38
10

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

2
  • Thanks Andrew, this teaches me some good practice here. I didn't know about the every node option. Jun 15, 2011 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. Jun 15, 2011 at 16:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .