diff options
Diffstat (limited to 'Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tikz-trees.tex')
-rw-r--r-- | Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tikz-trees.tex | 218 |
1 files changed, 122 insertions, 96 deletions
diff --git a/Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tikz-trees.tex b/Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tikz-trees.tex index ac0a00bda5f..cdf2cf45456 100644 --- a/Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tikz-trees.tex +++ b/Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tikz-trees.tex @@ -32,7 +32,7 @@ not downward as above. You can tell whether the author of a paper is a mathematician or a computer scientist by looking at the direction their trees grow. A computer scientist's trees will grow downward while a mathematician's tree will grow upward. Naturally, the -\emph{correct} way is the mathematician's way, which can be specify as +\emph{correct} way is the mathematician's way, which can be specified as follows: \begin{codeexample}[] \begin{tikzpicture} @@ -45,6 +45,12 @@ follows: \end{tikzpicture} \end{codeexample} +In \tikzname, there are two ways of specifying trees: Using either the +|graph| path operation, which is covered in +Section~\ref{section-library-graphs}, or using the |child| path +operation, which is covered in the present section. Both methods have +their advantages. + In \tikzname, trees are specified by adding \emph{children} to a node on a path using the |child| operation: @@ -86,7 +92,7 @@ node {root} child [red] foreach \name in {1,2} {node {\name}} \end{codeexample} the effect will be the same as if you had said \begin{codeexample}[code only] -node {root} child[red] {node {1}} child[ref] {node {2}} +node {root} child[red] {node {1}} child[red] {node {2}} \end{codeexample} When you write \begin{codeexample}[code only] @@ -114,7 +120,7 @@ node {root} child[left] {node[left] {1}} child[right] {node[right] {2}} -\subsection{Child Paths and the Child Nodes} +\subsection{Child Paths and Child Nodes} For each |child| of a root node, its \meta{child path} is inserted at a specific location in the picture (the placement rules are discussed @@ -133,9 +139,9 @@ the second child, no child node is specified and, thus, it is just As for any normal node, you can give the child node a name, shift it around, or use options to influence how it is rendered. \begin{codeexample}[] -\begin{tikzpicture} +\begin{tikzpicture}[sibling distance=15mm] \node[rectangle,draw] {root} - child {node[circle,draw] (left node) {left}} + child {node[circle,draw,yshift=-5mm] (left node) {left}} child {node[ellipse,draw] (right node) {right}}; \draw[dashed,->] (left node) -- (right node); \end{tikzpicture} @@ -208,7 +214,7 @@ first and/or second child of |parent|. Here is an example: \begin{codeexample}[] -\begin{tikzpicture} +\begin{tikzpicture}[sibling distance=15mm] \node (root) {root} child child { @@ -231,7 +237,8 @@ example: \begin{codeexample}[] \begin{tikzpicture} - [thick,level 2/.style={sibling distance=10mm}] + [thick,level 1/.style={sibling distance=15mm}, + level 2/.style={sibling distance=10mm}] \coordinate child[red] {child child} child[green] {child child[blue]}; @@ -284,16 +291,16 @@ Here is the set of rules: \begin{codeexample}[code only] \begin{tikzpicture} - \path - [...] % Options apply to the whole tree - node[...] {root} % Options apply to the root node only - [...] % Options apply to all children - child[...] % Options apply to this child and all its children - { - node[...] {} % Options apply to the child node only - ... - } - child[...] % Options apply to this child and all its children + \scoped + [...] % Options apply to the whole tree + \node[...] {root} % Options apply to the root node only + [...] % Options apply to all children + child[...] % Options apply to this child and all its children + { + node[...] {} % Options apply to the child node only + ... + } + child[...] % Options apply to this child and all its children ; \end{tikzpicture} \end{codeexample} @@ -358,7 +365,9 @@ evenly spaced or their centers are evenly distributed. Calculating good positions is especially difficult since a good position for the first child may depend on the size of the last child. -In \tikzname, a comparatively simple approach is taken to placing the +In basic \tikzname, when you do not make use of the graph drawing +facilities explained in Part~\ref{part-gd}, a comparatively simple +approach is taken to placing the children. In order to compute a child's position, all that is taken into account is the number of the current child in the list of children and the number of children in this list. Thus, if a node has @@ -391,7 +400,7 @@ is given by the |level distance|. {\catcode`\|=12 \begin{codeexample}[] -\begin{tikzpicture} +\begin{tikzpicture}[sibling distance=15mm, level distance=15mm] \path [help lines] node (root) {root} [grow=-10] @@ -637,7 +646,7 @@ will not be rendered. \end{codeexample} In the next example, the top and bottom nodes are aligned at the top - and the bottom. + and the bottom, respectively. \begin{codeexample}[] \begin{tikzpicture} [level distance=2cm,growth parent anchor=north, @@ -662,7 +671,7 @@ will not be rendered. The effect of executing the macro should be the following: It should transform the coordinate system in such a way that the origin becomes the place where the current child should be anchored. When - the macro is called, the current coordinate system will be setup + the macro is called, the current coordinate system will be set up such that the anchor of the parent node is in the origin. Thus, in each call, the \meta{macro name} must essentially do a shift to the child's origin. When the macro is called, the \TeX\ counter @@ -690,18 +699,34 @@ edge called the |edge from parent|. This edge is added to the \begin{pathoperation}{edge from parent}{\opt{\oarg{options}}} This path operation can only be used inside \meta{child paths} and - should be given at the end, possibly followed by node specifications - (we will come to that). If a \meta{child path} does not contain this - operation, it will be added at the end of the \meta{child path} - automatically. - - This operation has several effects. The most important is that it - inserts the current ``edge from parent path'' into the child - path. The edge from parent path can be set using the following - key: + should be given at the end, possibly followed by \meta{node + specifications} like |node {a}|. If a \meta{child path} does not + contain this operation, it will be added at the end of the + \meta{child path} automatically. + + By default, this operation does the following: + \begin{enumerate} + \item The following style is executed: + \begin{stylekey}{/tikz/edge from parent (initially draw)} + This style is inserted right before the |edge from parent path| and + before the \meta{options} are inserted. +\begin{codeexample}[] +\begin{tikzpicture} + [edge from parent/.style={draw,red,thick}] + \node {root} + child {node {left} edge from parent[dashed]} + child {node {right} + child {node {child}} + child {node {child} edge from parent[draw=none]} + }; +\end{tikzpicture} +\end{codeexample} + \end{stylekey} + \item Next, the \meta{options} are executed. + \item Next, the text stored in the following key is inserted: \begin{key}{/tikz/edge from parent path=\meta{path} (initially \normalfont code shown below)} - This options allows you to set the edge from parent path to a new + This option allows you to set the |edge from parent path| to a new path. Initially, this path is the following: \begin{codeexample}[code only] (\tikzparentnode\tikzparentanchor) -- (\tikzchildnode\tikzchildanchor) @@ -719,7 +744,8 @@ edge called the |edge from parent|. This edge is added to the effects. For example, we could replace the straight line by a curve as follows: \begin{codeexample}[] -\begin{tikzpicture}[edge from parent path= +\begin{tikzpicture}[level distance=15mm, sibling distance=15mm, + edge from parent path= {(\tikzparentnode.south) .. controls +(0,-1) and +(0,1) .. (\tikzchildnode.north)}] \node {root} @@ -731,71 +757,14 @@ edge called the |edge from parent|. This edge is added to the \end{tikzpicture} \end{codeexample} - Further useful edge from parent paths are defined in the tree + Further useful |edge from parent path|s are defined in the tree library, see Section~\ref{section-tree-library}. - \end{key} - - As said before, the anchors in the default edge from parent path - are empty. However, you can set them using the following keys: - \begin{key}{/tikz/child anchor=\meta{anchor} (initially border)} - Specifies the anchor where the edge from parent meets the child - node by setting the macro |\tikzchildanchor| to - |.|\meta{anchor}. - - If you specify |border| as the \meta{anchor}, then the macro - |\tikzchildanchor| is set to the empty string. The effect of - this is that the edge from the parent will meet the child on the - border at an automatically calculated position. -\begin{codeexample}[] -\begin{tikzpicture} - \node {root} - [child anchor=north] - child {node {left} edge from parent[dashed]} - child {node {right} - child {node {child}} - child {node {child} edge from parent[draw=none]} - }; -\end{tikzpicture} -\end{codeexample} - \end{key} - - \begin{key}{/tikz/parent anchor=\meta{anchor} (initially border)} - This option works the same way as the |child anchor|, only for - the parent. - \end{key} - - Besides inserting the edge from parent path, the |edge from parent| - operation has another effect: The \meta{options} are inserted - directly before the edge from parent path and the following style is - also installed prior to inserting the path: - \begin{stylekey}{/tikz/edge from parent (initially draw)} - This style is inserted right before the edge from parent path and - before the \meta{options} are inserted. -\begin{codeexample}[] -\begin{tikzpicture} - [edge from parent/.style={draw,red,thick}] - \node {root} - child {node {left} edge from parent[dashed]} - child {node {right} - child {node {child}} - child {node {child} edge from parent[draw=none]} - }; -\end{tikzpicture} -\end{codeexample} - \end{stylekey} - - Note: The \meta{options} inserted before the edge from parent path - is added \emph{apply to the whole child path}. Thus, it is not - possible to, say, draw a circle in red as part of the child path and - then have an edge to parent in blue. However, as always, the child - node is a node and can be drawn in a totally different way. + + The nodes in a \meta{node specification} following the + |edge from parent| path command get executed as if the |pos| option + had been added to all these nodes, see also Section~\ref{section-pos-option}. - Finally, the |edge from parent| operation has one more effect: It - causes all nodes \emph{following} the operation to be placed on the - edge. This is the same effect as if you had added the |pos| option - to all these nodes, see also Section~\ref{section-pos-option}. - - As an example, consider the following code: + As an example, consider the following code: \begin{codeexample}[code only] \node (root) {} child {node (child) {} edge to parent node {label}}; \end{codeexample} @@ -805,7 +774,7 @@ edge called the |edge from parent|. This edge is added to the (root) -- (child) node [pos=0.5] {label} \end{codeexample} - Here is a more complicated example: + Here is a more complicated example: \begin{codeexample}[] \begin{tikzpicture} \node {root} @@ -828,7 +797,64 @@ edge called the |edge from parent|. This edge is added to the }; \end{tikzpicture} \end{codeexample} + + As said before, the anchors in the default |edge from parent path| + are empty. However, you can set them using the following keys: + \begin{key}{/tikz/child anchor=\meta{anchor} (initially border)} + Specifies the anchor where the edge from parent meets the child + node by setting the macro |\tikzchildanchor| to + |.|\meta{anchor}. + If you specify |border| as the \meta{anchor}, then the macro + |\tikzchildanchor| is set to the empty string. The effect of + this is that the edge from the parent will meet the child on the + border at an automatically calculated position. +\begin{codeexample}[] +\begin{tikzpicture} + \node {root} + [child anchor=north] + child {node {left} edge from parent[dashed]} + child {node {right} + child {node {child}} + child {node {child} edge from parent[draw=none]} + }; +\end{tikzpicture} +\end{codeexample} + \end{key} + + \begin{key}{/tikz/parent anchor=\meta{anchor} (initially border)} + This option works the same way as the |child anchor|, only for + the parent. + \end{key} + \end{key} + \end{enumerate} + + All of the above describes the standard functioning of the + |edge from parent| command. You may, however, sometimes need even + more fine-grained control (the graph drawing engine needs it, for + instance). In such cases the following key gives you complete + control: + \begin{key}{/tikz/edge from parent macro=\meta{macro}} + The \meta{macro} gets expanded each time the |edge from parent| + path operation is used. This \meta{macro} must take two parameters + and must expand to some text that is subsequently parsed by the + parser. The first parameter will be the set of \meta{options} that + where passed to the |edge from parent| command, the second + parameter will be the \meta{node specifications} that following + the command. + + The standard behaviour of drawing a straight line from the parent + node to the child node could be achieved by setting the + \meta{macro} to the following: +\begin{codeexample}[code only] +\def\mymacro#1#2{ + [style=edge from parent, #1] + (\tikzparentnode\tikzparentanchor) -- #2 (\tikzchildnode\tikzchildanchor) +} +\end{codeexample} + Note that |#2| is placed between |--| and the node to ensure that + nodes are put ``on top'' of the line. + \end{key} \end{pathoperation} |