1

As stated in this brilliant answer tikz splines can be genrated this way (code is shamelessly copied):

\documentclass{article}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\draw [gray!50, xshift=4cm]  (0,0) -- (1,1) -- (2,-2) -- (3,0);
\draw [cyan, xshift=4cm] plot [smooth, tension=2] coordinates { (0,0) (1,1) (2,-2) (3,0)};
\end{tikzpicture}
\end{document}

However, what I need is a spline that becomes transparent at the second coordinate and becomes visible again after the third one.

Simply using two splines does not work, because it changes the shape of the spline between the first and second, and third and forth coordinate.

Is there a way of doing that?

kyra
  • 327

1 Answers1

4

One option to do this with clip, you can use method taken from this answer How can I invert a 'clip' selection within TikZ.

  • First we create path (rectangle) which covers the central part of cyan line.
  • Second use method described in the answer above to invert clip.

Code

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[remember picture,overlay]

% A path that follows the edges of the current page
\tikzstyle{reverseclip}=[insert path={(current page.north east) --
  (current page.south east) --
  (current page.south west) --
  (current page.north west) --
  (current page.north east)}
]

\draw [gray!50]  (0,0) -- (1,1) -- (2,-2) -- (3,0);

\begin{scope}
\begin{pgfinterruptboundingbox} % To make sure our clipping path does not mess up the placement of the picture

\path[clip](1,1)rectangle(2,-2)[reverseclip];
\end{pgfinterruptboundingbox}
\draw [cyan] plot [smooth, tension=2] coordinates { (0,0) (1,1) (2,-2) (3,0)};
\end{scope}


\end{tikzpicture}
\end{document}

Output

enter image description here

Salim Bou
  • 17,021
  • 2
  • 31
  • 76