PGF/TikZ Manual

The TikZ and PGF Packages
Manual for version 3.1.10

Libraries

74 To Path Library

  • TikZ Library topaths

  • \usetikzlibrary{topaths} % and plain
    \usetikzlibrary[topaths] % Cont

    This library provides predefined to paths for use with the to path operation. After loading this package, you can say for instance to [loop] to add a loop to a node.

    This library is loaded automatically by TikZ, so you do not need to load it yourself.

74.1 Straight Lines

The following style installs a to path that is simply a straight line from the start coordinate to the target coordinate.

  • /tikz/line to(no value)

  • Causes a straight line to be added to the path upon a to or an edge operation.

    (-tikz- diagram)


    \tikz {\draw (0,0) to[line to] (1,0);}
74.2 Move-Tos

The following style installs a to path that simply “jumps” to the target coordinate.

74.3 Curves

The curve to style causes the to path to be set to a curve. The exact way this curve looks can be influenced via a number of options.

  • /tikz/curve to(no value)

  • Specifies that the to path should be a curve. This curve will leave the start coordinate at a certain angle, which can be specified using the out option. It reaches the target coordinate also at a certain angle, which is specified using the in option. The control points of the curve are at a certain distance that is computed in different ways, depending on which options are set.

    All of the following options implicitly cause the curve to style to be installed.

    • /tikz/out=angle(no default)

    • The angle at which the curve leaves the start coordinate. If the start coordinate is a node, the start coordinate is the point on the border of the node at the given angle. The control point will, thus, lie at a certain distance in the direction angle from the start coordinate.

      (-tikz- diagram)


      \begin{tikzpicture}[out=45,in=135]
      \draw (0,0) to (1,0)
      (0,0) to (2,0)
      (0,0) to (3,0);
      \end{tikzpicture}
    • /tikz/in=angle(no default)

    • The angle at which the curve reaches the target coordinate.

    • /tikz/relative=true or false (default true)

    • This option tells TikZ whether the in and out angles should be considered absolute or relative. Absolute means that an out angle of 30\(^\circ \) means that the curve leaves the start coordinate at an angle of 30\(^\circ \) relative to the paper (unless, of course, further transformations have been installed). A relative angle is, by comparison, measured relative to a straight line from the start coordinate to the target coordinate. Thus, a relative angle of 30\(^\circ \) means that the curve will bend to the left from the line going straight from the start to the target. For the target, the relative coordinate is measured in the same manner, namely relative to the line going from the start to the target. Thus, an angle of 150\(^\circ \) means that the curve will reach target coming slightly from the left.

      (-tikz- diagram)


      \begin{tikzpicture}[out=45,in=135,relative]
      \draw (0,0) to (1,0)
      to (2,1)
      to (2,2);
      \end{tikzpicture}

      (-tikz- diagram)


      \begin{tikzpicture}[out=90,in=90,relative]
      \node [circle,draw] (a) at (0,0) {a};
      \node [circle,draw] (b) at (1,1) {b};
      \node [circle,draw] (c) at (2,2) {c};

      \path (a) edge (b)
      edge (c);
      \end{tikzpicture}
    • /tikz/bend right=angle (default last value)

    • Works like the bend left option, only the bend is to the other side.

    • /tikz/bend angle=angle(no default)

    • Sets the angle to be used by the bend left or bend right, but without actually selecting the curve to or the relative option. This is useful for globally specifying a bend angle for a whole picture.

    • /tikz/looseness=number (no default, initially 1)

    • This number specifies how “loose” the curve will be. In detail, the following happens: TikZ computes the distance between the start and the target coordinate (if the start and/or target coordinate are nodes, the distance is computed between the points on their border). This distance is then multiplied by a fixed factor and also by the factor number. The resulting distance, let us call it \(d\), is then used as the distance of the control points from the start and target coordinates.

      The fixed factor has been chosen in such a way that if number is 1, if the in and out angles differ by 90\(^\circ \), then a quarter circle results:

      (-tikz- diagram)(-tikz- diagram)


      \tikz \draw (0,0) to [out=0,in=-90] (1,1);
      \tikz \draw (0,0) to [out=0,in=-90,looseness=0.5] (1,1);
    • /tikz/out looseness=number(no default)

    • Specifies the looseness factor for the out distance only.

    • /tikz/in looseness=number(no default)

    • Specifies the looseness factor for the in distance only.

    • /tikz/min distance=distance(no default)

    • If the computed distance for the start and target coordinates are below distance, then distance is used instead.

    • /tikz/max distance=distance(no default)

    • If the computed distance for the start and target coordinates are above distance, then distance is used instead.

    • /tikz/out min distance=distance(no default)

    • The minimum distance set only for the start coordinate.

    • /tikz/out max distance=distance(no default)

    • The maximum distance set only for the start coordinate.

    • /tikz/in min distance=distance(no default)

    • The minimum distance set only for the target coordinate.

    • /tikz/in max distance=distance(no default)

    • The maximum distance set only for the target coordinate.

    • /tikz/distance=distance(no default)

    • Set the minimum and maximum distance to the same value distance. Note that this causes any computed distance \(d\) to be ignored and distance to be used instead.

      (-tikz- diagram)


      \begin{tikzpicture}[out=45,in=135,distance=1cm]
      \draw (0,0) to (1,0)
      (0,0) to (2,0)
      (0,0) to (3,0);
      \end{tikzpicture}
    • /tikz/out distance=distance(no default)

    • Sets the minimum and maximum out distance.

    • /tikz/in distance=distance(no default)

    • Sets the minimum and maximum in distance.

    • /tikz/out control=coordinate(no default)

    • This option causes the coordinate to be used as the start control point. All computations of \(d\) are ignored. You can use a coordinate like +(1,0) to specify a point relative to the start coordinate.

    • /tikz/in control=coordinate(no default)

    • This option causes the coordinate to be used as the target control point. You can use a coordinate like +(1,0) to specify a point relative to the end coordinate.

    • /tikz/controls=coordinate and coordinate(no default)

    • This option causes the coordinates to be used as control points.

      (-tikz- diagram)


      \tikz \draw (0,0) to [controls=+(90:1) and +(90:1)] (3,0);
74.4 Loops
  • /tikz/loop(no value)

  • This key is similar to the curve to key, but differs in the following ways: First, the actual target coordinate is ignored and the start coordinate is used as the target coordinate. Thus, it is allowed not to provide any target coordinate, which can be useful with unnamed nodes. Second, the looseness is set to 8 and the min distance to 5mm. These settings result in rather nice loops when the opening angle (difference between in and out) is 30\(^\circ \).

    (-tikz- diagram)


    \begin{tikzpicture}
    \node [circle,draw] {a} edge [in=30,out=60,loop] ();
    \end{tikzpicture}
  • /tikz/loop above(style, no value)

  • Sets the loop style and sets in and out angles such that loop is above the node. Furthermore, the above option is set, which causes a node label to be placed at the correct position.

    (-tikz- diagram)


    \begin{tikzpicture}
    \node [circle,draw] {a} edge [loop above] node {x} ();
    \end{tikzpicture}
  • /tikz/loop below(style, no value)

  • Works like the previous option.

  • /tikz/loop left(style, no value)

  • Works like the previous option.

  • /tikz/loop right(style, no value)

  • Works like the previous option.