I have a simple question and hope for a simple answer: why does closing a path with dash pattern not work if the dash length exceeds the length of the path?
\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[dash pattern=on 5cm off 16cm,blue,ultra thick]
(0,0) -- (1,0) -- (1,1) -- (0,1) -- cycle;
\begin{scope}[xshift=2cm]
\draw[blue,ultra thick]
(0,0) -- (1,0) -- (1,1) -- (0,1) -- cycle;
\end{scope}
\end{tikzpicture}
\end{document}
If you look closely, you'll notice that the left contour does not close, i.e. the bottom left corner is "screwed up". This is despite the fact that the dash exceeds (5cm) the length of the path (4cm). Why is that and how can one fix this?
Notice that I am not interested in a manual fix of the sort \draw[blue,ultra thick] (0,0) -- (1,0) -- (1,1) -- (0,1) -- (0,-\pgflinewidth/2);. I would, however, also be interested in a solution using decorations. This is because the present question is closely related to this nice question and the discussion below it. If you come up with a solution based on decorations that is different from this post in that it is less hacky, more transparent and does not mix decorations and meta decorations in an intricate way, this would be very interesting, but perhaps fit better as an answer to the partner question. (I am, however, not interested in a pure decorations solution in which one has to "quantize" the steps in such a way that the square gets redrawn.) That is, I would prefer answers without decorations to this question.



subpath(0, length p + eps) of p, so let Metapost loop around and append a minimal start segment of the path after the normal path. Then it is just a normal corner ans everything works. – Marcel Krüger Aug 21 '18 at 23:24\draw[dashed,blue,ultra thick] (0,0) -- (1,0) -- (1,1) -- (0,1) -- cycle;, couldn't you? (Yes, I know that the dash pattern is not glorious then, and that the cheating dashes were created to fix this. What I did not appreciate so far is that even a single dash is problematic.) But your suggestion on the extra path is very clever and promising. – Aug 21 '18 at 23:27dash patternif the first segment is not longer than the path? – Marcel Krüger Aug 21 '18 at 23:50