1

As an example, I wish to draw two segments, one in blue, one in red.

\begin{tikzpicture}
\draw [color=blue](0,0)--(1,1);
\draw [color=red](1,0)--(0,1);
\end{tikzpicture}

I wish I could issue only one draw or path command such as this (the path is computed externally) :

\begin{tikzpicture}
\draw [color=blue] (0,0)--(1,1) [color=red] (1,0)--(0,1)
\end{tikzpicture}

But this will draw two red lines since "color" is global to the path and the red color will supercede the blue color in the whole path.

Is there a path command, let's say \stop, that would make

\draw [color=blue] (0,0)--(1,1) \stop [color=red] (1,0)--(0,1);

equivalent to

\draw [color=blue] (0,0)--(1,1);
\draw [color=red] (1,0)--(0,1);

?

P.S. 1 : the external program can then produce a single phrase : "[color=blue] (0,0)--(1,1) \stop [color=red] (1,0)--(0,1);" I can put behind the "\draw" command.

P.S. 2 : without entering too much details, it is difficult to make the program produce "\draw" because during the transfer to Latex, it is interpreted by Latex not Tikz.

1

No you can't. Either you loose the line joining features (miter etc.) or you use one color per stroke if used the typical -- operation.

The stopping part can be done via to or edge operations and the above statement also apply to them (in different contexts)

\draw (0,0) edge[draw=red]  (1,1) 
      (1,0) edge[draw=blue] (0,1);

This gives a different colored X arms.

As a side note, use draw=red instead of color=red to just change the stroke color.

  • Thanks for closing definitely this door. I will look for another way round ! I dream of a time when most options will be made local when inside of brackets !! – user1771398 Nov 24 '15 at 10:27
  • @user1771398 This is not a limit of TikZ / pgf but rather of PDF / Postscript. – Paul Gaborit Nov 24 '15 at 10:31
  • @PaulGaborit But still, isn't it within the power of Tikz-pgf to parse '\draw [color=blue] (0,0)--(1,1) \flushToPostScript [color=red] (1,0)--(0,1);' as an equivalent to '\draw [color=blue] (0,0)--(1,1); \draw [color=red] (1,0)--(0,1);' ? – user1771398 Nov 24 '15 at 10:49
  • @user1771398 As noted by percusse, with PDF/Postscript, you can't change the drawing color of a path without loose the line joining features. – Paul Gaborit Nov 24 '15 at 11:39
  • @PaulGaborit I understand that, due to PDF/Postscript, a serie of ( , )--( , )-- ... --( , ) can only be in one color ; for me, no problem since I want two different lines (that is with an interruption between the two) of different color ; if it were otherwise, I would just repeat the common point of the two lines. In other words, I am ready to trade a line interruption to be able to change color (or other parameters) within a path. Thanks for explanations. – user1771398 Nov 24 '15 at 12:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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