Draw a path with dashed start and solid end

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}

Another way (partially automated and gives you control over the amount of dashes):

\documentclass[a4paper]{article}
\usepackage[english]{babel}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\begin{figure}[h!]
\begin{tikzpicture}[every path/.style={>=latex}]

% Normal dashed line
\draw[thick,black] (0,1) -- (1,1);
\draw[->,thick,black,dashed] (1,1) -- (4,1) node[anchor=west] {Normal dashed line};

% Specify dashed line starting coordinate and length
\draw[thick,black] (0,0) -- (1,0);
\def\x{1}; \def\y{0}; \def\length{3} \def\N{4}; 
% Draw dashed line using normal lines
\pgfmathsetmacro{\step}{(0.5+1/(4*\N))*\length/\N}; \pgfmathparse{\N-1};
\foreach \i in {0,...,\pgfmathresult} {\draw[thick,black] (\x+2*\i*\step,\y) -- (\x+2*\i*\step+\step,\y);}; 
\draw[->,thick,black] (\x+\length,\y) -- (\x+\length+0.01,\y) node[anchor=west] {Custom dashed line};

\end{tikzpicture}
\end{figure}
\end{document}

This simply mimicks a normal dashed line by drawing multiple lines after each other. Parameters are \x for the starting x-coordinate, \y for the y-level of the line, \length for the length in coordinates of the line and \N for the amount of stripes.

arrows

Tags:

Paths

Tikz Pgf