3

I'm drawing a bended line with TikZ, say using

\draw (0,0) to[out=-45, in=-135] (0,5);

Is there a way to define a dash pattern such that the first third of this arc is fully present, the second third is dashed and the last third is invisible? In other words, can the dash pattern somehow depend on the length of the line?

For straight lines, I can imagine a workaround by just splitting the line into three parts, but this is (at least for me) not really possible in this case.

2

You could use a decoration to get the desired result.

\documentclass{article}
\usepackage{tikz}

\usetikzlibrary{decorations.pathmorphing}
\tikzset{
  every curvepart/.style={},
  curvepart/.style n args={3}{
    postaction={black,every curvepart,#1, decorate,
      decoration={curveto,
        pre=moveto, pre length=#2*\pgfdecoratedinputsegmentlength,
        post=moveto, post length=(1-#3)*\pgfdecoratedinputsegmentlength
  }}}
}

\begin{document}
\begin{tikzpicture}
  \path[
    every curvepart/.style={draw,very thick},
    curvepart={solid}{0}{1/3},
    curvepart={dashed}{1/3}{2/3},
  ](0,0) to[out=-45, in=-135](0,5);
\end{tikzpicture}
%
\begin{tikzpicture}
  \path[draw,orange!25,line width=4pt,
    every curvepart/.style={draw,very thick},
    curvepart={solid,purple}{0}{1/3},
    curvepart={dashed,green}{1/3}{2/3},
    curvepart={dotted,blue}{2/3}{1}
  ](0,0) to[out=-45, in=-135](0,5);
\end{tikzpicture}
%
\begin{tikzpicture}
  \path[draw,orange!25,line width=4pt,
    every curvepart/.style={draw,dashed,very thick},
    curvepart={purple}{.1}{.2},
    curvepart={blue}{.5}{.6},
    curvepart={}{.9}{1},
    curvepart={green}{.3}{.4},
    curvepart={orange!80!black}{.7}{.8}
  ](0,0) to[out=-45, in=-135](0,5);
\end{tikzpicture}
\end{document}

enter image description here

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.