diff options
author | Karl Berry <karl@freefriends.org> | 2010-10-29 00:31:31 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2010-10-29 00:31:31 +0000 |
commit | 6bc1f5497cfb2f56d65c80a4c36ea3bad6dc046c (patch) | |
tree | f7751da75030fb1e06653eeb44e579fcee09c65f /Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tutorial-nodes.tex | |
parent | ed0c7c756e441b2d2ba3633da233fc24361ac0d3 (diff) |
pgf 2.10 (28oct10)
git-svn-id: svn://tug.org/texlive/trunk@20236 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tutorial-nodes.tex')
-rw-r--r-- | Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tutorial-nodes.tex | 237 |
1 files changed, 129 insertions, 108 deletions
diff --git a/Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tutorial-nodes.tex b/Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tutorial-nodes.tex index 0f5e1a2d185..f9c5eb8de53 100644 --- a/Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tutorial-nodes.tex +++ b/Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tutorial-nodes.tex @@ -1,4 +1,4 @@ -% Copyright 2006 by Till Tantau +% Copyright 2006 by Tilo Tantau % % This file may be distributed and/or modified % @@ -14,7 +14,7 @@ In this second tutorial we explore the node mechanism of Hagen must give a talk tomorrow about his favorite formalism for distributed systems: Petri nets! Hagen used to give his talks using a -blackboard and everyone seemed to be perfectly concent with +blackboard and everyone seemed to be perfectly concent with % TODOsp: concent --> consent? this. Unfortunately, his audience has been spoiled recently with fancy projector-based presentations and there seems to be a certain amount of peer pressure that this Petri nets should also be drawn using a @@ -43,7 +43,7 @@ capacities. The graphic should look like this, ideally: \node [place] (s) [below=of c1,label=above:$s\le 3$] {}; \node [place] (c2) [below=of s] {}; \node [place,tokens=1] (w2) [below=of c2] {}; - + \node [transition] (e1) [left=of c1] {} edge [pre,bend left] (w1) edge [post,bend right] (s) @@ -53,7 +53,7 @@ capacities. The graphic should look like this, ideally: edge [pre,bend right] (w2) edge [post,bend left] (s) edge [post] (c2); - + \node [transition] (l1) [right=of c1] {} edge [pre] (c1) edge [pre,bend left] (s) @@ -64,7 +64,7 @@ capacities. The graphic should look like this, ideally: edge [pre,bend right] (s) edge [post,bend left] node {2} (w2); \end{scope} - + \begin{scope}[xshift=6cm] % Second net \node [place,tokens=1] @@ -76,7 +76,7 @@ capacities. The graphic should look like this, ideally: \node [place] (c2') [below=of s1',xshift=5mm] {}; \node [place,tokens=1] (w2') [below=of c2'] {}; - + \node [transition] (e1') [left=of c1'] {} edge [pre,bend left] (w1') edge [post] (s1') @@ -88,7 +88,7 @@ capacities. The graphic should look like this, ideally: edge [post] (s1') edge [pre] (s2') edge [post] (c2'); - + \node [transition] (l1') [right=of c1'] {} edge [pre] (c1') edge [pre] (s1') @@ -110,7 +110,7 @@ capacities. The graphic should look like this, ideally: \draw [shorten >=1mm,-to,thick,decorate,decoration={snake,amplitude=.4mm,segment length=2mm,pre=moveto,pre length=1mm,post length=2mm}] (r1) -- (r2) - node [above=1mm,midway,text width=3cm,text centered] + node [above=1mm,midway,text width=3cm,align=center] {replacement of the \textcolor{red}{capacity} by \textcolor{red}{two places}}; \end{tikzpicture} @@ -131,7 +131,7 @@ special arrow tip used in the graphic, the |decoration.pathmorphing| library for the ``snaking line'' in the middle, the background library for the two rectangular areas that are behind the two main parts of the picture, the |fit| library to easily compute the sizes of -these ractangles, and the |placements| library for placing nodes +these rectangles, and the |positioning| library for placing nodes relative to other nodes. @@ -143,7 +143,7 @@ When using \LaTeX\ use: \documentclass{article} % say \usepackage{tikz} -\usetikzlibrary{arrows,decorations.pathmorphing,backgrounds,placments,fit} +\usetikzlibrary{arrows,decorations.pathmorphing,backgrounds,positioning,fit,petri} \begin{document} \begin{tikzpicture} @@ -160,7 +160,7 @@ When using plain \TeX\ use: \begin{codeexample}[code only] %% Plain TeX file \input tikz.tex -\usetikzlibrary{arrows,decorations.pathmorphing,backgrounds,placments,fit} +\usetikzlibrary{arrows,decorations.pathmorphing,backgrounds,positioning,fit,petri} \baselineskip=12pt \hsize=6.3truein \vsize=8.7truein @@ -173,17 +173,19 @@ When using plain \TeX\ use: \subsubsection{Setting up the Environment in Con\TeX t} -When using Con\TeX\ use: +When using Con\TeX\ use\footnote{Note that \pgfname/\tikzname{} is not + supported by recent Con\TeX t versions (like mark IV, the + Lua\TeX-aware part of Con\TeX t).}: \begin{codeexample}[code only] %% ConTeXt file \usemodule[tikz] -\usetikzlibrary[arrows,decorations.pathmorphing,backgrounds,placments,fit] +\usetikzlibrary[arrows,decorations.pathmorphing,backgrounds,positioning,fit,petri] \starttext \starttikzpicture \draw (0,0) -- (1,1); \stoptikzpicture -\startext +\stoptext \end{codeexample} @@ -218,18 +220,18 @@ a node can get a \emph{name} for later reference. In Hagen's picture we will use nodes for the places and for the transitions of the Petri net (the places are the circles, the transitions are the rectangles). Let us start with the upper half of -the left Petir net. In this upper half we have three places and two +the left Petri net. In this upper half we have three places and two transitions. Instead of drawing three circles and two rectangles, we use three nodes of shape |circle| and two nodes of shape |rectangle|. \begin{codeexample}[] \begin{tikzpicture} - \path ( 0,2) node [shape=circle,draw] {} - ( 0,1) node [shape=circle,draw] {} - ( 0,0) node [shape=circle,draw] {} + \path ( 0,2) node [shape=circle,draw] {} + ( 0,1) node [shape=circle,draw] {} + ( 0,0) node [shape=circle,draw] {} ( 1,1) node [shape=rectangle,draw] {} - (-1,1) node [shape=rectangle,draw] {}; + (-1,1) node [shape=rectangle,draw] {}; \end{tikzpicture} \end{codeexample} @@ -256,7 +258,7 @@ So, the code |(0,2) node [shape=circle,draw] {}| means the following: temporarily suspend the construction of the main path while the node is build. This node will be a |circle| around an empty text. This circle is to be |draw|n, but not filled or otherwise used. Once this -whole node is constructed, it is saved until after the +whole node is constructed, it is saved until after the main path is finished. Then, it is drawn.'' Then following |(0,1) node [shape=circle,draw] {}| then has the following effect: ``Continue the main path with a move-to to |(0,1)|. Then construct a @@ -280,11 +282,11 @@ last coordinate. Hagen can then write the following: \begin{codeexample}[] \begin{tikzpicture} - \path node at ( 0,2) [shape=circle,draw] {} - node at ( 0,1) [shape=circle,draw] {} - node at ( 0,0) [shape=circle,draw] {} + \path node at ( 0,2) [shape=circle,draw] {} + node at ( 0,1) [shape=circle,draw] {} + node at ( 0,0) [shape=circle,draw] {} node at ( 1,1) [shape=rectangle,draw] {} - node at (-1,1) [shape=rectangle,draw] {}; + node at (-1,1) [shape=rectangle,draw] {}; \end{tikzpicture} \end{codeexample} @@ -296,15 +298,15 @@ be improved further: The |\node| command is an abbreviation for \begin{codeexample}[] \begin{tikzpicture} \node at ( 0,2) [circle,draw] {}; - \node at ( 0,1) [circle,draw] {}; - \node at ( 0,0) [circle,draw] {}; + \node at ( 0,1) [circle,draw] {}; + \node at ( 0,0) [circle,draw] {}; \node at ( 1,1) [rectangle,draw] {}; - \node at (-1,1) [rectangle,draw] {}; + \node at (-1,1) [rectangle,draw] {}; \end{tikzpicture} \end{codeexample} Hagen likes this syntax much better than the previous one. Note that -Hagen has also omitted the |shape=| since, like |color=|, \tikzname\ +Hagen has also omitted the |shape=| since, like |color=|, \tikzname\ allows you to omit the |shape=| if there is no confusion. @@ -318,10 +320,10 @@ different colors, resulting in the following code: \begin{codeexample}[] \begin{tikzpicture}[thick] \node at ( 0,2) [circle,draw=blue!50,fill=blue!20] {}; - \node at ( 0,1) [circle,draw=blue!50,fill=blue!20] {}; - \node at ( 0,0) [circle,draw=blue!50,fill=blue!20] {}; + \node at ( 0,1) [circle,draw=blue!50,fill=blue!20] {}; + \node at ( 0,0) [circle,draw=blue!50,fill=blue!20] {}; \node at ( 1,1) [rectangle,draw=black!50,fill=black!20] {}; - \node at (-1,1) [rectangle,draw=black!50,fill=black!20] {}; + \node at (-1,1) [rectangle,draw=black!50,fill=black!20] {}; \end{tikzpicture} \end{codeexample} @@ -338,10 +340,10 @@ places and another style for transitions: [place/.style={circle,draw=blue!50,fill=blue!20,thick}, transition/.style={rectangle,draw=black!50,fill=black!20,thick}] \node at ( 0,2) [place] {}; - \node at ( 0,1) [place] {}; - \node at ( 0,0) [place] {}; + \node at ( 0,1) [place] {}; + \node at ( 0,0) [place] {}; \node at ( 1,1) [transition] {}; - \node at (-1,1) [transition] {}; + \node at (-1,1) [transition] {}; \end{tikzpicture} \end{codeexample} @@ -361,10 +363,10 @@ adds some space around the text. The amount is set using the option place/.style={circle,draw=blue!50,fill=blue!20,thick}, transition/.style={rectangle,draw=black!50,fill=black!20,thick}] \node at ( 0,2) [place] {}; - \node at ( 0,1) [place] {}; - \node at ( 0,0) [place] {}; + \node at ( 0,1) [place] {}; + \node at ( 0,0) [place] {}; \node at ( 1,1) [transition] {}; - \node at (-1,1) [transition] {}; + \node at (-1,1) [transition] {}; \end{tikzpicture} \end{codeexample} @@ -376,7 +378,7 @@ a longer text, it will be larger, but if the text is empty, then the node will have |minimum size|. This option is also useful to ensure that several nodes containing different amounts of text have the same size. The options |minimum height| and |minimum width| allow you to -specify the minimum height and width independently. +specify the minimum height and width independently. So, what Hagen needs to do is to provide |minimum size| for the nodes. To be on the safe side, he also sets |inner sep=0pt|. This @@ -389,12 +391,12 @@ the automatically added space. [place/.style={circle,draw=blue!50,fill=blue!20,thick, inner sep=0pt,minimum size=6mm}, transition/.style={rectangle,draw=black!50,fill=black!20,thick, - inner sep=0pt,minimum size=4mm}] + inner sep=0pt,minimum size=4mm}] \node at ( 0,2) [place] {}; - \node at ( 0,1) [place] {}; - \node at ( 0,0) [place] {}; + \node at ( 0,1) [place] {}; + \node at ( 0,0) [place] {}; \node at ( 1,1) [transition] {}; - \node at (-1,1) [transition] {}; + \node at (-1,1) [transition] {}; \end{tikzpicture} \end{codeexample} @@ -426,10 +428,10 @@ transition/.style={rectangle,draw=black!50,fill=black!20,thick, % ... setup styles \begin{tikzpicture} \node (waiting 1) at ( 0,2) [place] {}; - \node (critical 1) at ( 0,1) [place] {}; - \node (semaphore) at ( 0,0) [place] {}; + \node (critical 1) at ( 0,1) [place] {}; + \node (semaphore) at ( 0,0) [place] {}; \node (leave critical) at ( 1,1) [transition] {}; - \node (enter critical) at (-1,1) [transition] {}; + \node (enter critical) at (-1,1) [transition] {}; \end{tikzpicture} \end{codeexample} } @@ -437,7 +439,7 @@ transition/.style={rectangle,draw=black!50,fill=black!20,thick, Hagen is pleased to note that the names help in understanding the code. Names for nodes can be pretty arbitrary, but they should not contain commas, periods, parentheses, colons, and some other special -characters. However, they can contain underscores and hyphens. +characters. However, they can contain underscores and hyphens. The syntax for the |node| operation is quite liberal with respect to the order in which node names, the |at| specifier, and the options @@ -453,10 +455,10 @@ transition/.style={rectangle,draw=black!50,fill=black!20,thick, \begin{codeexample}[] \begin{tikzpicture} \node[place] (waiting 1) at ( 0,2) {}; - \node[place] (critical 1) at ( 0,1) {}; - \node[place] (semaphore) at ( 0,0) {}; + \node[place] (critical 1) at ( 0,1) {}; + \node[place] (semaphore) at ( 0,0) {}; \node[transition] (leave critical) at ( 1,1) {}; - \node[transition] (enter critical) at (-1,1) {}; + \node[transition] (enter critical) at (-1,1) {}; \end{tikzpicture} \end{codeexample} } @@ -481,19 +483,19 @@ transition/.style={rectangle,draw=black!50,fill=black!20,thick, \begin{codeexample}[] \begin{tikzpicture} \node[place] (waiting) {}; - \node[place] (critical) [below=of waiting] {}; - \node[place] (semaphore) [below=of critical] {}; + \node[place] (critical) [below=of waiting] {}; + \node[place] (semaphore) [below=of critical] {}; \node[transition] (leave critical) [right=of critical] {}; - \node[transition] (enter critical) [left=of critical] {}; + \node[transition] (enter critical) [left=of critical] {}; \end{tikzpicture} \end{codeexample} } -With the |replacements| library loaded, when an option like |below| -is followed by |of|, then the position of the node is shifted +With the |positioning| library loaded, when an option like |below| +is followed by |of|, then the position of the node is shifted in such a manner that it is placed at the distance |node distance| in the specified direction of the given direction. The |node distance| is -either the distance between the centers of the nodes (when the +either the distance between the centers of the nodes (when the |on grid| option is set to true) or the distance between the borders (when the |on grid| option is set to false, which is the default). @@ -519,12 +521,12 @@ transition/.style={rectangle,draw=black!50,fill=black!20,thick, \begin{codeexample}[] \begin{tikzpicture} \node[place] (waiting) {}; - \node[place] (critical) [below=of waiting] {}; - \node[place] (semaphore) [below=of critical] {}; + \node[place] (critical) [below=of waiting] {}; + \node[place] (semaphore) [below=of critical] {}; \node[transition] (leave critical) [right=of critical] {}; - \node[transition] (enter critical) [left=of critical] {}; + \node[transition] (enter critical) [left=of critical] {}; - \node [red,above] at (semaphore.north) {$s\le 3$}; + \node [red,above] at (semaphore.north) {$s\le 3$}; \end{tikzpicture} \end{codeexample} } @@ -538,7 +540,7 @@ This is a general approach that will ``always work.'' |label=above:$s\le 3$|. This option is interpreted as follows: We want a node above the |semaphore| node and this node should read ``$s \le 3$.'' Instead of |above| we could also use things like - |below left| before the colon or a number like |60|. + |below left| before the colon or a number like |60|. { \tikzset{place/.style={circle,draw=blue!50,fill=blue!20,thick, inner sep=0pt,minimum size=6mm}, @@ -547,11 +549,11 @@ transition/.style={rectangle,draw=black!50,fill=black!20,thick, \begin{codeexample}[] \begin{tikzpicture} \node[place] (waiting) {}; - \node[place] (critical) [below=of waiting] {}; + \node[place] (critical) [below=of waiting] {}; \node[place] (semaphore) [below=of critical, - label=above:$s\le3$] {}; + label=above:$s\le3$] {}; \node[transition] (leave critical) [right=of critical] {}; - \node[transition] (enter critical) [left=of critical] {}; + \node[transition] (enter critical) [left=of critical] {}; \end{tikzpicture} \end{codeexample} } @@ -576,13 +578,13 @@ transition/.style={rectangle,draw=black!50,fill=black!20,thick, transition/.style={rectangle,draw=black!50,fill=black!20,thick, inner sep=0pt,minimum size=4mm}} \begin{codeexample}[] -\begin{tikzpicture}[every label/.style={red}] +\begin{tikzpicture}[every label/.style={red}] \node[place] (waiting) {}; - \node[place] (critical) [below=of waiting] {}; + \node[place] (critical) [below=of waiting] {}; \node[place] (semaphore) [below=of critical, - label=above:$s\le3$] {}; + label=above:$s\le3$] {}; \node[transition] (leave critical) [right=of critical] {}; - \node[transition] (enter critical) [left=of critical] {}; + \node[transition] (enter critical) [left=of critical] {}; \end{tikzpicture} \end{codeexample} } @@ -611,10 +613,10 @@ transition/.style={rectangle,draw=black!50,fill=black!20,thick, \begin{codeexample}[] \begin{tikzpicture} \node[place] (waiting) {}; - \node[place] (critical) [below=of waiting] {}; - \node[place] (semaphore) [below=of critical] {}; + \node[place] (critical) [below=of waiting] {}; + \node[place] (semaphore) [below=of critical] {}; \node[transition] (leave critical) [right=of critical] {}; - \node[transition] (enter critical) [left=of critical] {}; + \node[transition] (enter critical) [left=of critical] {}; \draw [->] (critical.west) -- (enter critical.east); \end{tikzpicture} \end{codeexample} @@ -631,10 +633,10 @@ transition/.style={rectangle,draw=black!50,fill=black!20,thick, \begin{codeexample}[] \begin{tikzpicture} \node[place] (waiting) {}; - \node[place] (critical) [below=of waiting] {}; - \node[place] (semaphore) [below=of critical] {}; + \node[place] (critical) [below=of waiting] {}; + \node[place] (semaphore) [below=of critical] {}; \node[transition] (leave critical) [right=of critical] {}; - \node[transition] (enter critical) [left=of critical] {}; + \node[transition] (enter critical) [left=of critical] {}; \draw [->] (enter critical.east) -- (critical.west); \draw [->] (waiting.west) .. controls +(left:5mm) and +(up:5mm) .. (enter critical.north); @@ -657,10 +659,10 @@ transition/.style={rectangle,draw=black!50,fill=black!20,thick, \begin{codeexample}[] \begin{tikzpicture} \node[place] (waiting) {}; - \node[place] (critical) [below=of waiting] {}; - \node[place] (semaphore) [below=of critical] {}; + \node[place] (critical) [below=of waiting] {}; + \node[place] (semaphore) [below=of critical] {}; \node[transition] (leave critical) [right=of critical] {}; - \node[transition] (enter critical) [left=of critical] {}; + \node[transition] (enter critical) [left=of critical] {}; \draw [->] (enter critical) -- (critical); \draw [->] (waiting) .. controls +(left:8mm) and +(up:8mm) .. (enter critical); @@ -682,7 +684,7 @@ anchor by hand. Hagen would now like to simplify the curve operation somehow. It turns out that this can be accomplished using a special path operation: the |to| operation. This operation takes many options (you can even define -new ones yourself). One pair of option is useful for Hagen: The pair +new ones yourself). One pair of options is useful for Hagen: The pair |in| and |out|. These options take angles at which a curve should leave or reach the start or target coordinates. Without these options, a straight line is drawn: @@ -695,10 +697,10 @@ transition/.style={rectangle,draw=black!50,fill=black!20,thick, \begin{codeexample}[] \begin{tikzpicture} \node[place] (waiting) {}; - \node[place] (critical) [below=of waiting] {}; - \node[place] (semaphore) [below=of critical] {}; + \node[place] (critical) [below=of waiting] {}; + \node[place] (semaphore) [below=of critical] {}; \node[transition] (leave critical) [right=of critical] {}; - \node[transition] (enter critical) [left=of critical] {}; + \node[transition] (enter critical) [left=of critical] {}; \draw [->] (enter critical) to (critical); \draw [->] (waiting) to [out=180,in=90] (enter critical); \end{tikzpicture} @@ -718,10 +720,10 @@ transition/.style={rectangle,draw=black!50,fill=black!20,thick, \begin{codeexample}[] \begin{tikzpicture} \node[place] (waiting) {}; - \node[place] (critical) [below=of waiting] {}; - \node[place] (semaphore) [below=of critical] {}; + \node[place] (critical) [below=of waiting] {}; + \node[place] (semaphore) [below=of critical] {}; \node[transition] (leave critical) [right=of critical] {}; - \node[transition] (enter critical) [left=of critical] {}; + \node[transition] (enter critical) [left=of critical] {}; \draw [->] (enter critical) to (critical); \draw [->] (waiting) to [bend right=45] (enter critical); \draw [->] (enter critical) to [bend right=45] (semaphore); @@ -734,10 +736,10 @@ edges: Using the |edge| path operation. This operation is very similar to the |to| operation, but there is one important difference: Like a node the edge generated by the |edge| operation is not part of the main path, but is added only later. This may not seem very important, -but is has some nice consequences. For example, every edge can have +but it has some nice consequences. For example, every edge can have its own arrow tips and its own color and so one and, still, all the edges can be given on the same path. This allows Hagen to write the -following: +following: { @@ -748,8 +750,8 @@ transition/.style={rectangle,draw=black!50,fill=black!20,thick, \begin{codeexample}[] \begin{tikzpicture} \node[place] (waiting) {}; - \node[place] (critical) [below=of waiting] {}; - \node[place] (semaphore) [below=of critical] {}; + \node[place] (critical) [below=of waiting] {}; + \node[place] (semaphore) [below=of critical] {}; \node[transition] (leave critical) [right=of critical] {}; \node[transition] (enter critical) [left=of critical] {} edge [->] (critical) @@ -779,8 +781,8 @@ transition/.style={rectangle,draw=black!50,fill=black!20,thick, post/.style={->,shorten >=1pt,>=stealth',semithick}] \node[place] (waiting) {}; - \node[place] (critical) [below=of waiting] {}; - \node[place] (semaphore) [below=of critical] {}; + \node[place] (critical) [below=of waiting] {}; + \node[place] (semaphore) [below=of critical] {}; \node[transition] (leave critical) [right=of critical] {} edge [pre] (critical) @@ -830,21 +832,21 @@ each |to| operation. For Hagen that |auto| option is not really necessary since the two ``2'' labels could also easily be placed ``by hand.'' However, in a complicated plot with numerous edges automatic placement can be a -blessing. +blessing. { \tikzset{place/.style={circle,draw=blue!50,fill=blue!20,thick, inner sep=0pt,minimum size=6mm}, transition/.style={rectangle,draw=black!50,fill=black!20,thick, inner sep=0pt,minimum size=4mm}, -pre/.style={<-,shorten <=1pt,>=stealth',semithick}, -post/.style={->,shorten >=1pt,>=stealth',semithick}} +pre/.style={<-,shorten <=1pt,>=stealth',semithick}, +post/.style={->,shorten >=1pt,>=stealth',semithick}} \begin{codeexample}[] % Styles as before \begin{tikzpicture}[bend angle=45] \node[place] (waiting) {}; - \node[place] (critical) [below=of waiting] {}; - \node[place] (semaphore) [below=of critical] {}; + \node[place] (critical) [below=of waiting] {}; + \node[place] (semaphore) [below=of critical] {}; \node[transition] (leave critical) [right=of critical] {} edge [pre] (critical) @@ -866,7 +868,7 @@ With the node mechanism Hagen can now easily create the two Petri nets. What he is unsure of is how he can create the snaked line between the nets. -For this he can use a \emph{decoration}. +For this he can use a \emph{decoration}. To draw the snake, Hagen only needs to set the two options |decoration=snake| and |decorate| on the path. This causes all lines of the path to be replaced by @@ -883,7 +885,7 @@ Well, that does not look quite right, yet. The problem is that the snake happens to end exactly at the position where the arrow begins. Fortunately, there is an option that helps here. Also, the snake should be a bit smaller, which can be influenced by even more -options. +options. \begin{codeexample}[] \begin{tikzpicture} @@ -894,17 +896,34 @@ options. \end{codeexample} Now Hagen needs to add the text above the snake. This text is a bit -challenging since it is a multi-line text. To typeset such text, Hagen -needs to specify a width for the text and he needs to specify that the -text should be centered. +challenging since it is a multi-line text. Hagen has two options for +this: First, he can specify an |align=center| and then use the |\\| +command to enforce the line breaks at the desired positions. +\begin{codeexample}[] +\begin{tikzpicture} + \draw [->,decorate, + decoration={snake,amplitude=.4mm,segment length=2mm,post length=1mm}] + (0,0) -- (3,0) + node [above,align=center,midway] + { + replacement of\\ + the \textcolor{red}{capacity}\\ + by \textcolor{red}{two places} + }; +\end{tikzpicture} +\end{codeexample} + +Instead of specifying the line breaks ``by hand,'' Hagen can also +specify a width for the text and let \TeX\ perform the line breaking +for him: \begin{codeexample}[] \begin{tikzpicture} \draw [->,decorate, decoration={snake,amplitude=.4mm,segment length=2mm,post length=1mm}] (0,0) -- (3,0) - node [above,text width=3cm,text centered,midway] + node [above,text width=3cm,align=center,midway] { replacement of the \textcolor{red}{capacity} by \textcolor{red}{two places} @@ -945,14 +964,14 @@ nodes and coordinates given as parameters to the |fit| option. inner sep=0pt,minimum size=6mm}, transition/.style={rectangle,draw=black!50,fill=black!20,thick, inner sep=0pt,minimum size=4mm}, -pre/.style={<-,shorten <=1pt,>=stealth',semithick}, +pre/.style={<-,shorten <=1pt,>=stealth',semithick}, post/.style={->,shorten >=1pt,>=stealth',semithick}} \begin{codeexample}[] % Styles as before \begin{tikzpicture}[bend angle=45] \node[place] (waiting) {}; - \node[place] (critical) [below=of waiting] {}; - \node[place] (semaphore) [below=of critical] {}; + \node[place] (critical) [below=of waiting] {}; + \node[place] (semaphore) [below=of critical] {}; \node[transition] (leave critical) [right=of critical] {} edge [pre] (critical) @@ -964,7 +983,7 @@ post/.style={->,shorten >=1pt,>=stealth',semithick}} edge [post,bend right] (semaphore); \begin{pgfonlayer}{background} - \node [fill=black!30,fit=(waiting) (critical) (semaphore) + \node [fill=black!30,fit=(waiting) (critical) (semaphore) (leave critical) (enter critical)] {}; \end{pgfonlayer} \end{tikzpicture} @@ -1004,13 +1023,14 @@ Now comes the code for the nets: red place/.style={place,draw=red!75,fill=red!20}, every label/.style={red}, every picture/.style={on grid,node distance=1.3cm,>=stealth',bend angle=45,auto}} +\tikzexternaldisable \begin{codeexample}[pre=\begin{tikzpicture},post=\end{tikzpicture}] \node [place,tokens=1] (w1) {}; \node [place] (c1) [below=of w1] {}; \node [place] (s) [below=of c1,label=above:$s\le 3$] {}; \node [place] (c2) [below=of s] {}; \node [place,tokens=1] (w2) [below=of c2] {}; - + \node [transition] (e1) [left=of c1] {} edge [pre,bend left] (w1) edge [post,bend right] (s) @@ -1037,8 +1057,9 @@ every transition/.style={thick,draw=black!75,fill=black!20}, red place/.style= {place,draw=red!75,fill=red!20}, every label/.style={red}, every picture/.style={on grid,node distance=1.3cm,>=stealth',bend angle=45,auto}} +\tikzexternaldisable \begin{codeexample}[pre=\begin{tikzpicture},post=\end{tikzpicture}] - \begin{scope}[xshift=6cm] + \begin{scope}[xshift=6cm] \node [place,tokens=1] (w1') {}; \node [place] (c1') [below=of w1'] {}; \node [red place] (s1') [below=of c1',xshift=-5mm] @@ -1047,7 +1068,7 @@ every picture/.style={on grid,node distance=1.3cm,>=stealth',bend angle=45,auto} [label=right:$\bar s$] {}; \node [place] (c2') [below=of s1',xshift=5mm] {}; \node [place,tokens=1] (w2') [below=of c2'] {}; - + \node [transition] (e1') [left=of c1'] {} edge [pre,bend left] (w1') edge [post] (s1') @@ -1083,7 +1104,7 @@ The code for the background and the snake is the following: \draw [shorten >=1mm,-to,thick,decorate, decoration={snake,amplitude=.4mm,segment length=2mm, pre=moveto,pre length=1mm,post length=2mm}] - (r1) -- (r2) node [above=1mm,midway,text width=3cm,text centered] + (r1) -- (r2) node [above=1mm,midway,text width=3cm,align=center] {replacement of the \textcolor{red}{capacity} by \textcolor{red}{two places}}; \end{tikzpicture} \end{codeexample} |