When, in TikZ, I apply a path morphing decoration (say, "snake") and specify the segment length option, I often finish up with a straight segment at the end of the path, such as
which often is not the desired behavior. It happens in case there is no room for the whole decoration segment at the end of path. If I do not specify the segment length, it's all right, but I want to have some control over the decoration parameters.
Do you know if there is a way to set the segment length softly in such a way that it is modified a bit automatically in order to get rid of these straight segments?
The picture was produced with the following code:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
\draw[decorate, decoration = {snake, segment length = .4cm}] (0,0) -- (2,0);
\end{tikzpicture}
\end{document}
Best Answer
This is a slightly adapted version of my answer to Nicer wavy line with TikZ. This version doesn't insist on drawing a full sine wave, but will be happy with half periods as well (i.e. it can start and end with an upward arch, while the previous version would always start with an upward and end with a downward arch):