# 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:

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?

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.

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

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)
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)

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)

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)
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

## Related Questions

### Using package genealogytree, how do I make invisible a particular line connecting two nodes?

1  Asked on June 19, 2021 by kevin-coates

### Remove vertical space induced by substack

1  Asked on June 19, 2021 by paulprogrammernoob

### Inverse search on AUCTeX opens file in new Emacs window instead of main Emacs window – how to avoid that?

2  Asked on June 19, 2021 by benedikt-ahrens

### Changing to large letters in the header

2  Asked on June 19, 2021

### Authoryear style and how to make entries appear as Author:Year in the footnotes?

1  Asked on June 19, 2021 by dmitry-starostin

### 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

### “Error Extra }, or forgotten \$” in a diagram using forest environment

2  Asked on June 19, 2021 by chrm

### Nodes in PGFPlots Get Cut Off

1  Asked on June 19, 2021 by arszilla

### beamer > beamercolorbox > Text with Shadow or Glow

1  Asked on June 19, 2021

### Suppress section number, keep label

1  Asked on June 19, 2021

### Overlap filled area plots

2  Asked on June 19, 2021

### Equivalent of cftchapternumwidth when using book class?

2  Asked on June 19, 2021

### siunitx: aligning infty in an S column

1  Asked on June 19, 2021

### Multiple tags/right-justified text in unaligned environments using amsmath

1  Asked on June 19, 2021 by mike-van-dyke

### Index with dashes to show levels

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

### Beamer: use glyphs from smaller font size, but enlarge

2  Asked on June 19, 2021 by japreiss

### How to end the supplementary part?

3  Asked on June 19, 2021 by brigitte-bruijns

### ntheorem: Manually placing end-of-proof symbol in an equation

1  Asked on June 19, 2021

### How to draw an electric circuit with the help of ‘circuitikz’?

1  Asked on June 19, 2021