[Tex/LaTex] Draw a path with dashed start and solid end

pathstikz-pgf

I want to draw a line or path with dashed line style at its begining and a solid line at the end, but in only one path (I mean, not drawing two path), something like :

\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (3,0) -- (1,0)[dashed] -- (0,0)[solid] ;
\end{tikzpicture}
\end{document}

Best Answer

If those are to be straight line segments, it couldn't get any simpler. It gets interesting with curves. Enclosed are a few examples, and I agree - it's too complicated. Clipping is the most accurate way to tell where the solid part should stop, but it requires its own scope. Fading is good for smooth transition but probably would only give headache if the path doesn't run more or less in one direction. enter image description here

I'm quite sure there is a way to have a procedural stroke of the path, but I haven't found any information about that so far. I would personally enjoy a simple style that allows to easily morph the line type from start until end of a path, doing something similar to the second custom dash pattern but without all the typing. But for now, this is what I did:

\documentclass[12pt,a4paper]{minimal}
\usepackage{times}
\usepackage{tikz}
\usetikzlibrary{fadings}

\begin{document}
\begin{tikzpicture}[line width=1.5pt]


\node at (200pt,40pt) [label=right:{2 line segments}]{};
% for straight segments this is the easiest:
%
\draw[dashed] (200pt,40pt) -- (60pt,40pt);
\draw (60pt,40pt) -- (0pt,40pt);


\node at (200pt,10pt) [label=right:{custom dash pattern}]{};
% for curves you can specify custom dash pattern, but it's cumbersome 
% having to specify every singly dash untill the line becomes solid:
%
\draw[dash pattern=on 10pt off 10pt on 10pt off 10pt on 10pt off 10pt on 10pt off 10pt on 10pt off 10pt on 10pt off 10pt on 10pt off 10pt on 100pt] (200pt,10pt) .. controls (40pt,40pt)  and (90pt,-30pt) .. (0,20pt);


\node at (200pt,-10pt) [label=right:{custom dash pattern}]{};
% it does however allow for nice density modifications (but also by hand):
%
\draw[dash pattern=on 10pt off 9pt on 9pt off 8pt on 8pt off 7.3pt on 7.3pt off 6.7pt on 6.7pt off 6.3pt on 6.3pt off 5.9pt on 5.9pt off 5.4pt on 5.4pt off 5.0pt on 5.0pt off 4.0pt on 4.5pt off 3.0pt on 4.0pt off 2.4pt on 3.5pt off 1.8pt on 100pt] (200pt,-10pt) .. controls (40pt,20pt)  and (90pt,-50pt) .. (0,0pt);


\node at (200pt,-30pt) [label=right:{2 curves: dashed $+$ clipped solid}]{};
% now there's 2 paths - a long dashed one and a clipped solid one:
%
\begin{scope}
\clip (-5pt,-70pt) rectangle (60pt,5pt);
\draw (200pt,-30pt) .. controls (40pt,0pt)  and (90pt,-70pt) .. (0,-20pt);
\end{scope}
\draw[dashed] (200pt,-30pt) .. controls (40pt,0pt)  and (90pt,-70pt) .. (0,-20pt);


\node at (200pt,-50pt) [label=right:{2 curves: dashed $+$ faded solid}]{};
% for a gradient toning down of the solid line you can use fading:
%
\draw[path fading=east] (200pt,-50pt) .. controls (40pt,-20pt) and (90pt,-90pt) .. (0,-40pt);
\draw[dashed,path fading=west] (200pt,-50pt) .. controls (40pt,-20pt) and (90pt,-90pt) .. (0,-40pt);


\end{tikzpicture}
\end{document}