| 1 |
% Copyright 2019 by Till Tantau |
| 2 |
% |
| 3 |
% This file may be distributed and/or modified |
| 4 |
% |
| 5 |
% 1. under the LaTeX Project Public License and/or |
| 6 |
% 2. under the GNU Free Documentation License. |
| 7 |
% |
| 8 |
% See the file doc/generic/pgf/licenses/LICENSE for more details. |
| 9 |
|
| 10 |
|
| 11 |
\section{To Path Library} |
| 12 |
\label{library-to-paths} |
| 13 |
|
| 14 |
\begin{tikzlibrary}{topaths} |
| 15 |
This library provides predefined to paths for use with the |to| path |
| 16 |
operation. After loading this package, you can say for instance |to [loop]| |
| 17 |
to add a loop to a node. |
| 18 |
|
| 19 |
This library is loaded automatically by \tikzname, so you do not need to |
| 20 |
load it yourself. |
| 21 |
\end{tikzlibrary} |
| 22 |
|
| 23 |
|
| 24 |
\subsection{Straight Lines} |
| 25 |
|
| 26 |
The following style installs a to path that is simply a straight line from the |
| 27 |
start coordinate to the target coordinate. |
| 28 |
|
| 29 |
\begin{key}{/tikz/line to} |
| 30 |
Causes a straight line to be added to the path upon a |to| or an |edge| |
| 31 |
operation. |
| 32 |
% |
| 33 |
\begin{codeexample}[] |
| 34 |
\tikz {\draw (0,0) to[line to] (1,0);} |
| 35 |
\end{codeexample} |
| 36 |
% |
| 37 |
\end{key} |
| 38 |
|
| 39 |
|
| 40 |
\subsection{Move-Tos} |
| 41 |
|
| 42 |
The following style installs a to path that simply ``jumps'' to the target |
| 43 |
coordinate. |
| 44 |
|
| 45 |
\begin{key}{/tikz/move to} |
| 46 |
Causes a move to be added to the path upon a |to| or an |edge| operation. |
| 47 |
% |
| 48 |
\begin{codeexample}[] |
| 49 |
\tikz \draw (0,0) to[line to] (1,0) |
| 50 |
to[move to] (2,0) to[line to] (3,0); |
| 51 |
\end{codeexample} |
| 52 |
% |
| 53 |
\end{key} |
| 54 |
|
| 55 |
|
| 56 |
\subsection{Curves} |
| 57 |
|
| 58 |
The |curve to| style causes the to path to be set to a curve. The exact way |
| 59 |
this curve looks can be influenced via a number of options. |
| 60 |
|
| 61 |
\begin{key}{/tikz/curve to} |
| 62 |
Specifies that the |to path| should be a curve. This curve will leave the |
| 63 |
start coordinate at a certain angle, which can be specified using the |out| |
| 64 |
option. It reaches the target coordinate also at a certain angle, which is |
| 65 |
specified using the |in| option. The control points of the curve are at a |
| 66 |
certain distance that is computed in different ways, depending on which |
| 67 |
options are set. |
| 68 |
|
| 69 |
All of the following options implicitly cause the |curve to| style to be |
| 70 |
installed. |
| 71 |
|
| 72 |
\begin{key}{/tikz/out=\meta{angle}} |
| 73 |
The angle at which the curve leaves the start coordinate. If the start |
| 74 |
coordinate is a node, the start coordinate is the point on the border |
| 75 |
of the node at the given \meta{angle}. The control point will, thus, |
| 76 |
lie at a certain distance in the direction \meta{angle} from the start |
| 77 |
coordinate. |
| 78 |
% |
| 79 |
\begin{codeexample}[] |
| 80 |
\begin{tikzpicture}[out=45,in=135] |
| 81 |
\draw (0,0) to (1,0) |
| 82 |
(0,0) to (2,0) |
| 83 |
(0,0) to (3,0); |
| 84 |
\end{tikzpicture} |
| 85 |
\end{codeexample} |
| 86 |
\end{key} |
| 87 |
% |
| 88 |
\begin{key}{/tikz/in=\meta{angle}} |
| 89 |
The angle at which the curve reaches the target coordinate. |
| 90 |
\end{key} |
| 91 |
|
| 92 |
\begin{key}{/tikz/relative=\meta{true or false} (default true)} |
| 93 |
This option tells \tikzname\ whether the |in| and |out| angles should |
| 94 |
be considered absolute or relative. Absolute means that an |out| angle |
| 95 |
of 30$^\circ$ means that the curve leaves the start coordinate at an |
| 96 |
angle of 30$^\circ$ relative to the paper (unless, of course, further |
| 97 |
transformations have been installed). A \emph{relative} angle is, by |
| 98 |
comparison, measured relative to a straight line from the start |
| 99 |
coordinate to the target coordinate. Thus, a relative angle of |
| 100 |
30$^\circ$ means that the curve will bend to the left from the line |
| 101 |
going straight from the start to the target. For the target, the |
| 102 |
relative coordinate is measured in the same manner, namely relative to |
| 103 |
the line going from the start to the target. Thus, an angle of |
| 104 |
150$^\circ$ means that the curve will reach target coming slightly from |
| 105 |
the left. |
| 106 |
% |
| 107 |
\begin{codeexample}[] |
| 108 |
\begin{tikzpicture}[out=45,in=135,relative] |
| 109 |
\draw (0,0) to (1,0) |
| 110 |
to (2,1) |
| 111 |
to (2,2); |
| 112 |
\end{tikzpicture} |
| 113 |
\end{codeexample} |
| 114 |
|
| 115 |
\begin{codeexample}[] |
| 116 |
\begin{tikzpicture}[out=90,in=90,relative] |
| 117 |
\node [circle,draw] (a) at (0,0) {a}; |
| 118 |
\node [circle,draw] (b) at (1,1) {b}; |
| 119 |
\node [circle,draw] (c) at (2,2) {c}; |
| 120 |
|
| 121 |
\path (a) edge (b) |
| 122 |
edge (c); |
| 123 |
\end{tikzpicture} |
| 124 |
\end{codeexample} |
| 125 |
\end{key} |
| 126 |
|
| 127 |
\begin{key}{/tikz/bend left=\meta{angle} (default \normalfont last value)} |
| 128 |
This option sets |out=|\meta{angle}|,in=|$180-\meta{angle}$|,relative|. |
| 129 |
If no \meta{angle} is given, the last given |bend left| or |bend right| |
| 130 |
angle is used. |
| 131 |
% |
| 132 |
\begin{codeexample}[preamble={\usetikzlibrary{automata,positioning}}] |
| 133 |
\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid] |
| 134 |
\node[state,initial] (q_0) {$q_0$}; |
| 135 |
\node[state] (q_1) [right=of q_0] {$q_1$}; |
| 136 |
\node[state,accepting](q_2) [right=of q_1] {$q_2$}; |
| 137 |
|
| 138 |
\path[->] (q_0) edge node [above] {0} (q_1) |
| 139 |
edge [loop above] node {1} () |
| 140 |
edge [bend left] node [above] {1} (q_2) |
| 141 |
edge [bend right] node [below] {0} (q_2) |
| 142 |
(q_1) edge node [above] {1} (q_2); |
| 143 |
\end{tikzpicture} |
| 144 |
\end{codeexample} |
| 145 |
|
| 146 |
\begin{codeexample}[] |
| 147 |
\begin{tikzpicture} |
| 148 |
\foreach \angle in {0,45,...,315} |
| 149 |
\node[rectangle,draw=black!50] (\angle) at (\angle:2) {\angle}; |
| 150 |
|
| 151 |
\foreach \from/\to in {0/45,45/90,90/135,135/180, |
| 152 |
180/225,225/270,270/315,315/0} |
| 153 |
\path (\from) edge [->,bend right=22,looseness=0.8] (\to) |
| 154 |
edge [<-,bend left=22,looseness=0.8] (\to); |
| 155 |
\end{tikzpicture} |
| 156 |
\end{codeexample} |
| 157 |
\end{key} |
| 158 |
|
| 159 |
\begin{key}{/tikz/bend right=\meta{angle} (default \normalfont last value)} |
| 160 |
Works like the |bend left| option, only the bend is to the other side. |
| 161 |
\end{key} |
| 162 |
|
| 163 |
\begin{key}{/tikz/bend angle=\meta{angle}} |
| 164 |
Sets the angle to be used by the |bend left| or |bend right|, but |
| 165 |
without actually selecting the |curve to| or the |relative| option. |
| 166 |
This is useful for globally specifying a |bend angle| for a whole |
| 167 |
picture. |
| 168 |
\end{key} |
| 169 |
|
| 170 |
\begin{key}{/tikz/looseness=\meta{number} (initially 1)} |
| 171 |
This number specifies how ``loose'' the curve will be. In detail, the |
| 172 |
following happens: \tikzname\ computes the distance between the start |
| 173 |
and the target coordinate (if the start and/or target coordinate are |
| 174 |
nodes, the distance is computed between the points on their border). |
| 175 |
This distance is then multiplied by a fixed factor and also by the |
| 176 |
factor \meta{number}. The resulting distance, let us call it $d$, is |
| 177 |
then used as the distance of the control points from the start and |
| 178 |
target coordinates. |
| 179 |
|
| 180 |
The fixed factor has been chosen in such a way that if \meta{number} is |
| 181 |
|1|, if the |in| and |out| angles differ by 90$^\circ$, then a quarter |
| 182 |
circle results: |
| 183 |
% |
| 184 |
\begin{codeexample}[] |
| 185 |
\tikz \draw (0,0) to [out=0,in=-90] (1,1); |
| 186 |
\tikz \draw (0,0) to [out=0,in=-90,looseness=0.5] (1,1); |
| 187 |
\end{codeexample} |
| 188 |
\end{key} |
| 189 |
|
| 190 |
\begin{key}{/tikz/out looseness=\meta{number}} |
| 191 |
Specifies the looseness factor for the out distance only. |
| 192 |
\end{key} |
| 193 |
|
| 194 |
\begin{key}{/tikz/in looseness=\meta{number}} |
| 195 |
Specifies the looseness factor for the in distance only. |
| 196 |
\end{key} |
| 197 |
% |
| 198 |
\begin{key}{/tikz/min distance=\meta{distance}} |
| 199 |
If the computed distance for the start and target coordinates are below |
| 200 |
\meta{distance}, then \meta{distance} is used instead. |
| 201 |
\end{key} |
| 202 |
% |
| 203 |
\begin{key}{/tikz/max distance=\meta{distance}} |
| 204 |
If the computed distance for the start and target coordinates are above |
| 205 |
\meta{distance}, then \meta{distance} is used instead. |
| 206 |
\end{key} |
| 207 |
% |
| 208 |
\begin{key}{/tikz/out min distance=\meta{distance}} |
| 209 |
The minimum distance set only for the start coordinate. |
| 210 |
\end{key} |
| 211 |
% |
| 212 |
\begin{key}{/tikz/out max distance=\meta{distance}} |
| 213 |
The maximum distance set only for the start coordinate. |
| 214 |
\end{key} |
| 215 |
% |
| 216 |
\begin{key}{/tikz/in min distance=\meta{distance}} |
| 217 |
The minimum distance set only for the target coordinate. |
| 218 |
\end{key} |
| 219 |
% |
| 220 |
\begin{key}{/tikz/in max distance=\meta{distance}} |
| 221 |
The maximum distance set only for the target coordinate. |
| 222 |
\end{key} |
| 223 |
% |
| 224 |
\begin{key}{/tikz/distance=\meta{distance}} |
| 225 |
Set the minimum and maximum distance to the same value \meta{distance}. |
| 226 |
Note that this causes any computed distance $d$ to be ignored and |
| 227 |
\meta{distance} to be used instead. |
| 228 |
% |
| 229 |
\begin{codeexample}[] |
| 230 |
\begin{tikzpicture}[out=45,in=135,distance=1cm] |
| 231 |
\draw (0,0) to (1,0) |
| 232 |
(0,0) to (2,0) |
| 233 |
(0,0) to (3,0); |
| 234 |
\end{tikzpicture} |
| 235 |
\end{codeexample} |
| 236 |
% |
| 237 |
\end{key} |
| 238 |
% |
| 239 |
\begin{key}{/tikz/out distance=\meta{distance}} |
| 240 |
Sets the minimum and maximum out distance. |
| 241 |
\end{key} |
| 242 |
% |
| 243 |
\begin{key}{/tikz/in distance=\meta{distance}} |
| 244 |
Sets the minimum and maximum in distance. |
| 245 |
\end{key} |
| 246 |
% |
| 247 |
\begin{key}{/tikz/out control=\meta{coordinate}} |
| 248 |
This option causes the \meta{coordinate} to be used as the start |
| 249 |
control point. All computations of $d$ are ignored. You can use a |
| 250 |
coordinate like |+(1,0)| to specify a point relative to the start |
| 251 |
coordinate. |
| 252 |
\end{key} |
| 253 |
% |
| 254 |
\begin{key}{/tikz/in control=\meta{coordinate}} |
| 255 |
This option causes the \meta{coordinate} to be used as the target |
| 256 |
control point. You can use a coordinate like |+(1,0)| to specify |
| 257 |
a point relative to the \emph{end} coordinate. |
| 258 |
\end{key} |
| 259 |
% |
| 260 |
\begin{key}{/tikz/controls=\meta{coordinate}| and |\meta{coordinate}} |
| 261 |
This option causes the \meta{coordinate}s to be used as control points. |
| 262 |
% |
| 263 |
\begin{codeexample}[] |
| 264 |
\tikz \draw (0,0) to [controls=+(90:1) and +(90:1)] (3,0); |
| 265 |
\end{codeexample} |
| 266 |
\end{key} |
| 267 |
\end{key} |
| 268 |
|
| 269 |
|
| 270 |
\subsection{Loops} |
| 271 |
|
| 272 |
\begin{key}{/tikz/loop} |
| 273 |
This key is similar to the |curve to| key, but differs in the following |
| 274 |
ways: First, the actual target coordinate is ignored and the start |
| 275 |
coordinate is used as the target coordinate. Thus, it is allowed not to |
| 276 |
provide any target coordinate, which can be useful with unnamed nodes. |
| 277 |
Second, the |looseness| is set to |8| and the |min distance| to |5mm|. |
| 278 |
These settings result in rather nice loops when the opening angle |
| 279 |
(difference between |in| and |out|) is 30$^\circ$. |
| 280 |
% |
| 281 |
\begin{codeexample}[] |
| 282 |
\begin{tikzpicture} |
| 283 |
\node [circle,draw] {a} edge [in=30,out=60,loop] (); |
| 284 |
\end{tikzpicture} |
| 285 |
\end{codeexample} |
| 286 |
% |
| 287 |
\end{key} |
| 288 |
|
| 289 |
\begin{stylekey}{/tikz/loop above} |
| 290 |
Sets the |loop| style and sets in and out angles such that loop is above |
| 291 |
the node. Furthermore, the |above| option is set, which causes a node label |
| 292 |
to be placed at the correct position. |
| 293 |
% |
| 294 |
\begin{codeexample}[] |
| 295 |
\begin{tikzpicture} |
| 296 |
\node [circle,draw] {a} edge [loop above] node {x} (); |
| 297 |
\end{tikzpicture} |
| 298 |
\end{codeexample} |
| 299 |
% |
| 300 |
\end{stylekey} |
| 301 |
|
| 302 |
\begin{stylekey}{/tikz/loop below} |
| 303 |
Works like the previous option. |
| 304 |
\end{stylekey} |
| 305 |
% |
| 306 |
\begin{stylekey}{/tikz/loop left} |
| 307 |
Works like the previous option. |
| 308 |
\end{stylekey} |
| 309 |
% |
| 310 |
\begin{stylekey}{/tikz/loop right} |
| 311 |
Works like the previous option. |
| 312 |
\end{stylekey} |
| 313 |
% |
| 314 |
\begin{stylekey}{/tikz/every loop (initially {->,shorten >=1pt})} |
| 315 |
This style is installed at the beginning of every loop. |
| 316 |
% |
| 317 |
\begin{codeexample}[] |
| 318 |
\begin{tikzpicture}[every loop/.style={}] |
| 319 |
\draw (0,0) to [loop above] () to [loop right] () |
| 320 |
to [loop below] () to [loop left] (); |
| 321 |
\end{tikzpicture} |
| 322 |
\end{codeexample} |
| 323 |
% |
| 324 |
\end{stylekey} |
| 325 |
|
| 326 |
|
| 327 |
%%% Local Variables: |
| 328 |
%%% mode: latex |
| 329 |
%%% TeX-master: "pgfmanual-pdftex-version" |
| 330 |
%%% End: |