Skip to content
Browse files

Stretchable dash patterns #629

  • Loading branch information...
hmenke committed Jul 10, 2019
1 parent 9d18b41 commit d640cd539f9e2735e25709d88ecdd3e6106346c1
@@ -361,6 +361,25 @@ \subsubsection{Graphic Parameters: Dash Pattern}

\begin{key}{/tikz/dash expand off}
Makes the |off| part of a dash pattern expandable such that it can stretch.
This only works when there is a single |on| and a single |off| field and
requires the |decorations| library. Right now this option has to be
specified on the path where it is supposed to take effect after the |dash
pattern| option because the dash pattern has to be known at the point where
it is applied.
\begin{tikzpicture}[|-|, dash pattern=on 4pt off 2pt]
\draw [dash expand off] (0pt,30pt) -- (26pt,30pt);
\draw [dash expand off] (0pt,20pt) -- (24pt,20pt);
\draw [dash expand off] (0pt,10pt) -- (22pt,10pt);
\draw [dash expand off] (0pt, 0pt) -- (20pt, 0pt);

As for the line thickness, some predefined styles allow you to set the dashing

@@ -148,6 +148,42 @@

% use a decoration to expand the `off' section of a dash pattern.
dash expand off/.code={%
\ifcsname tikz@library@decorations@loaded\endcsname\else
\tikzerror{You need \string\usetikzlibrary{decorations} for ``dash offexpand''}%
% Parse \on and \off from the current path
% \dashphase = max(\on - \dashphase, 0)
\edef\dashphase{\the\dimexpr\pgfmathresult pt\relax}%
% \rest = \pgf@decorate@totalpathlength - \on
\edef\rest{\expandafter\pgf@sys@tonumber\dimexpr\pgf@decorate@totalpathlength - \on + 2\dimexpr\dashphase\relax\relax}%
% \onoff = \on + \off
% \nfullonoff = max(floor(\rest/\onoff), 1)
% \offexpand = max(\rest/\nfullonoff - \on, \off)

\tikzoption{draw opacity}{\tikz@addoption{\pgfsetstrokeopacity{#1}}}%

% Double draw options

0 comments on commit d640cd5

Please sign in to comment.
You can’t perform that action at this time.