6

In Can TikZ dashed lines emulate PSTricks dashed lines?, @Dominic asked if one can balance the dash pattern so that an ant living on the curve cannot distinguish the two ends.

Same problem arise naturally in PGF/TikZ decorations, for example

\documentclass[border=9,tikz]{standalone}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\tikz[decoration={snake,pre length=2mm,post length=2mm,segment length=4mm}]
    \draw[<->,decorate](0,0)--(2,0);
\end{document}

Notice that 2cm = 2mm + 2mm + 4mm*4, so the decoration should be exact. But even so I did not get a balanced decoration.

The general question is

Given pre length=post length and segment length, can one manipulate the underlying mechanism so that the de facto pre-length and post-length coincide?

P.S. the library calculates the total length of the curve for you.

3
  • It looks like the first little bend of path, i.e. the transition from the horizontal path to the decoration, is not accounted for. See for example this code: gist.github.com/TorbjornT/66cbd722d24af191b48f34657e66b4ef I don't know how to fix it though. Oct 5 '16 at 20:22
  • I guess you have discovered by now that TikZ has a switch off if distance left is less than <...> directive active for these. You can use Jake's tex.stackexchange.com/q/60733/3235 if you want
    – percusse
    Nov 9 '17 at 4:29
  • @percusse If I recall correctly, that option works pretty much like \foreach\i in{5,10,...,33} so the final length is not 33 but an awkward number 30. Thus we still have to do the pathetic computation...
    – Symbol 1
    Nov 9 '17 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.