AnswerBun.com

What do "-to" and "pre=moveto" do in TikZ arrows?

TeX - LaTeX Asked by Aria on December 21, 2020

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?

2 Answers

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.

Correct answer by AndréC on December 21, 2020

enter image description here

documentclass{article}
usepackage{tikz}
usetikzlibrary{decorations.pathmorphing}

begin{document}

begin{tikzpicture}[nodes={font=smallttfamily, 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};

    defx{    }
    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}

Answered by muzimuzhi Z on December 21, 2020

Add your own answers!

Related Questions

Remove vertical space induced by substack

1  Asked on June 19, 2021 by paulprogrammernoob

       

How to construct a confusion matrix in LaTeX?

7  Asked on June 19, 2021 by kkudi

   

Labels placed incorrectly in pst-jtree

0  Asked on June 19, 2021 by justin-colley

       

Nodes in PGFPlots Get Cut Off

1  Asked on June 19, 2021 by arszilla

     

Overlap filled area plots

2  Asked on June 19, 2021

   

Index with dashes to show levels

1  Asked on June 19, 2021 by ol-so-n-so

   

How to end the supplementary part?

3  Asked on June 19, 2021 by brigitte-bruijns

     

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP