
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}[nodes={font=\small\ttfamily, black, right}]
\draw[thick, red] (0, 0) -- (3, 0)
node {1.1 init with "thick, red"};
\draw[thick, red, shorten >=1mm, yshift=-.5cm]
(0, 0) -- (3, 0)
node {1.2 add "shorten >=1mm"};
\draw[|-|, yshift=-.4cm] (2.9, 0) -- node[above, font=\tiny] {1mm} (3, 0);
\draw[thick, red, shorten >=1mm, -to, yshift=-1cm]
(0, 0) -- (3, 0)
node {1.3 add arrow "-to"};
\begin{scope}[yshift=-2cm]
\draw[thick, red] (0, 0) -- (3, 0)
node {2.1 the same as 1.1};
\draw[thick, red, decorate,
decoration={snake},
yshift=-.5cm,
] (0, 0) -- (3, 0)
node {2.2 add "decorate, decoration=\{snake\}"};
\draw[thick, red, decorate,
decoration={snake, amplitude=.4mm, segment length=2mm},
yshift=-1cm,
] (0, 0) -- (3, 0)
node {2.3 add "decoration=\{..., amplitude=.4mm, segment length=2mm\}"};
\draw[thick, red, decorate,
decoration={
snake, amplitude=.4mm, segment length=2mm,
pre length=1mm, post length=2mm
},
yshift=-1.5cm,
] (0, 0) -- (3, 0)
node {2.4 add "decoration=\{..., pre length=1mm, post length=2mm\}"};
\draw[|-|, yshift=-1.4cm] (0, 0) -- node[above, font=\tiny] {1mm} (.1, 0);
\draw[|-|, yshift=-1.4cm] (2.8, 0) -- node[above, font=\tiny] {2mm} (3, 0);
\draw[thick, red, decorate,
decoration={
snake, amplitude=.4mm, segment length=2mm,
pre length=1mm, post length=2mm, pre=moveto
},
yshift=-2.0cm,
] (0, 0) -- (3, 0)
node {2.5 add "decoration=\{..., pre=moveto\}"};
\draw[|-|, yshift=-1.9cm] (0, 0) -- node[above, font=\tiny] {1mm} (.1, 0);
\end{scope}
\begin{scope}[yshift=-5cm]
\draw[thick, red, shorten >=1mm, -to, decorate,
decoration={
snake, amplitude=.4mm, segment length=2mm,
}
] (0, 0) -- (3, 0)
node {3.1 combine 1.3 and 2.3, not good};
\def\x{\ \ \ \ }
\draw[thick, red, shorten >=5mm, -to, decorate,
decoration={
snake, amplitude=.4mm, segment length=2mm,
},
yshift=-.5cm,
] (0, 0) -- (3, 0)
node[yshift=-.6cm, align=left] {
3.2 combine 1.3 and 2.3 and \\
\x use "shorten >=5mm" to show the real problem:\\
\x decoration is not shortened and a line is drawn \\
\x from real end (3, 0) to shortened end (2.5, 0).
};
\draw[|-|, yshift=-.4cm] (2.5, 0) -- node[above, font=\tiny] {5mm} (3, 0);
\draw[thick, red, shorten >=5mm, -to, decorate,
decoration={
snake, amplitude=.4mm, segment length=2mm,
post length=6mm, pre=moveto
},
yshift=-2.2cm,
] (0, 0) -- (3, 0)
node {3.2' add "decoration=\{..., post length=6mm, pre=moveto\}", ok};
\draw[thick, red, shorten >=1mm, -to, decorate,
decoration={
snake, amplitude=.4mm, segment length=2mm,
pre length=1mm, post length=2mm, pre=moveto
},
yshift=-2.7cm
] (0, 0) -- (3, 0)
node {3.3 combine 1.3 and 2.5, ok};
\draw[|-|, yshift=-2.6cm] (2.9, 0) -- node[above, font=\tiny] {1mm} (3, 0);
\end{scope}
\end{tikzpicture}
\end{document}
movetomeans to go to a certain place without drawing or colouring, it's a move. Herepre=moveto, pre length=1mmspecifies that the first millimetre nothing will be drawn, the decoration does nothing and nothing will be drawn the first millimetre of the path.Translated with www.DeepL.com/Translator (free version)
– AndréC Jul 30 '20 at 06:35-tois a now obsolete syntax initiated with the first versions of TikZ like1.18and to is the name of a predefined arrow. From now on, this is replaced by>. – AndréC Jul 30 '20 at 06:47-tois now replaced by->– AndréC Jul 30 '20 at 06:53shortenis now obsolete, but no other command is equivalent in version 3.1 so it is still used. You can find its definition in the1.18manual which can be downloaded here tikz manual 1.18 – AndréC Jul 30 '20 at 07:00shortenis obsolete? – Torbjørn T. Jul 30 '20 at 07:47post length, to get that accurate, you need asegment lengthappropriate to fit an integer number of "waves" in the available part of the path, see https://tex.stackexchange.com/questions/552354/ for a similar case. – Torbjørn T. Jul 30 '20 at 08:54tikzstyleis no longer documented in manual 3.0.1a or 3.1.5b,shortenis no longer documented. Both are still functional and undocumented, so the maintainer considers them obsolete. Otherwise, one would find the documentation forshortenin the latest manual and would not need to read the old manuals to understand their syntax. – AndréC Jul 30 '20 at 09:59\pgfsetshorten...? – Torbjørn T. Jul 30 '20 at 10:02