1

On page 61/1318 TikZ manual there is an example which I simplify and change it a little bit to create the following picture:

enter image description here

Here is my code:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary {arrows.meta}
\usetikzlibrary {decorations.pathmorphing}
\begin{document}

\begin{tikzpicture} %\draw [->,-to, thick, decorate, \draw [shorten >=1mm,-to, thick, decorate, red, decoration={snake,amplitude=.4mm,segment length=2mm, pre=moveto, pre length=1mm, post length=2mm}] (0,0) -- (3,0) node [above=1mm,align=center,midway, text width=3 cm] { replacement of\ the \textcolor{black}{capacity}\ by \textcolor{black}{two places} }; \draw [|-|] (2.8,0) -- (3,0); \draw [|-|] (0,0) -- (.1,0); \end{tikzpicture} \end{document}

I have these questions:

  1. What does -to do?
  2. What does pre=moveto do?
  3. Although post length=2mm according to the measurement using \draw [|-|] (2.8,0) -- (3,0); it looks post length is shorter.
  4. shorten >=1mm is applied where and how it works with pre and post lengths?
epR8GaYuh
  • 2,432
Aria
  • 1,523
  • 1
    When you decorate a path, you can have the decoration start a little later to start by drawing a straight line on a few millimetres and then decorate it properly. moveto means to go to a certain place without drawing or colouring, it's a move. Here pre=moveto, pre length=1mm specifies 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
  • 1
    -to is a now obsolete syntax initiated with the first versions of TikZ like 1.18 and to is the name of a predefined arrow. From now on, this is replaced by >. – AndréC Jul 30 '20 at 06:47
  • Thanks @AndreC, so -to is replaced by > ? I put > instead of -to and it did not work. – Aria Jul 30 '20 at 06:52
  • 1
    -to is now replaced by -> – AndréC Jul 30 '20 at 06:53
  • 1
    shorten is now obsolete, but no other command is equivalent in version 3.1 so it is still used. You can find its definition in the 1.18 manual which can be downloaded here tikz manual 1.18 – AndréC Jul 30 '20 at 07:00
  • @AndréC Where does it say that shorten is obsolete? – Torbjørn T. Jul 30 '20 at 07:47
  • 1
    Regarding the post length, to get that accurate, you need a segment length appropriate 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:54
  • @TorbjørnT. Just as tikzstyle is no longer documented in manual 3.0.1a or 3.1.5b, shorten is no longer documented. Both are still functional and undocumented, so the maintainer considers them obsolete. Otherwise, one would find the documentation for shorten in the latest manual and would not need to read the old manuals to understand their syntax. – AndréC Jul 30 '20 at 09:59
  • @AndréC Ehm, page 211 in the manual for 3.1.5b? Or page 1121 for the lower-level \pgfsetshorten...? – Torbjørn T. Jul 30 '20 at 10:02
  • @TorbjørnT. It's good news that this has been re-documented, it had disappeared from the 3.0.1a manual. A few years ago I had asked for this part to be put back, I see it has been done. Good. I'm very pleased. – AndréC Jul 30 '20 at 10:37

2 Answers2

5

It is customary here that there is only one question at a time. Nevertheless, I will answer only the first two questions, and I urge you to ask the other question again, which alone deserves further development.

First question : What does -to do?

In TikZ and pgf Manual for version 1.18, on page 322, we learn that -to is an arrow.

manual-1.18

Looking at its shape, we can see that it is the Computer Modern Rightarrow as shown on page 207 of the 3.1.5b manual. I quote:

Instead of a <arrow tip kind name>, you may also provide the name of a so-called shorthand. Shorthands look like normal arrow tip kind names and, indeed, you will often be using shorthands without noticing that you do. The idea is that instead of, say, Computer Modern Rightarrow you might wish to just write Rightarrow or perhaps just To or even just >.

Second question: What does pre=moveto do?

When you decorate a path, you can have the decoration start a little later to start by drawing a straight line on a few millimetres and then decorate it properly. moveto means to go to a certain place without drawing or colouring, it's a move. Here pre=moveto, pre length=1mm specifies that the first millimetre nothing will be drawn, the decoration does nothing and nothing will be drawn the first millimetre of the path.

AndréC
  • 24,137
5

enter image description here

\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 &quot;decorate, decoration=\{snake\}&quot;};

\draw[thick, red, decorate, 
  decoration={snake, amplitude=.4mm, segment length=2mm},
  yshift=-1cm,
] (0, 0) -- (3, 0)
  node {2.3 add &quot;decoration=\{..., amplitude=.4mm, segment length=2mm\}&quot;};

\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 &quot;decoration=\{..., pre length=1mm, post length=2mm\}&quot;};
\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 &quot;decoration=\{..., pre=moveto\}&quot;};
\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 &gt;=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 &quot;shorten &gt;=5mm&quot; 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 &gt;=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 &quot;decoration=\{..., post length=6mm, pre=moveto\}&quot;, ok};

\draw[thick, red, shorten &gt;=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}

muzimuzhi Z
  • 26,474