[next] [tail] [up]

### 14 Libraries

#### 14.1 Arrow Tip Library

\usepackage{pgflibraryarrows} % L A T E X
\input pgflibraryarrows.tex % plain T E X
\input pgflibraryarrows.tex % Con T E X t

  The package defines additional arrow tips, which are described below. See page 295 for the arrows tips that are defined by default. Note that neither the standard packages nor this package defines an arrow name containing > or <. These are left for the user to defined as he or she sees fit.

##### 14.1.1 Triangular Arrow Tips

latex' | yields thick and thin
latex' reversed | yields thick and thin
stealth' | yields thick and thin
stealth' reversed | yields thick and thin
triangle 90 | yields thick and thin
triangle 90 reversed | yields thick and thin
triangle 60 | yields thick and thin
triangle 60 reversed | yields thick and thin
triangle 45 | yields thick and thin
triangle 45 reversed | yields thick and thin
open triangle 90 | yields thick and thin
open triangle 90 reversed | yields thick and thin
open triangle 60 | yields thick and thin
open triangle 60 reversed | yields thick and thin
open triangle 45 | yields thick and thin
open triangle 45 reversed | yields thick and thin

##### 14.1.2 Barbed Arrow Tips

angle 90 | yields thick and thin
angle 90 reversed | yields thick and thin
angle 60 | yields thick and thin
angle 60 reversed | yields thick and thin
angle 45 | yields thick and thin
angle 45 reversed | yields thick and thin
hooks | yields thick and thin
hooks reversed | yields thick and thin

##### 14.1.3 Bracket-Like Arrow Tips

[-] | yields thick and thin
]-[ | yields thick and thin
(-) | yields thick and thin
)-( | yields thick and thin

##### 14.1.4 Circle and Diamond Arrow Tips

o | yields thick and thin
* | yields thick and thin
diamond | yields thick and thin
open diamond | yields thick and thin

##### 14.1.5 Partial Arrow Tips

left to | yields thick and thin
left to reversed | yields thick and thin
right to | yields thick and thin
right to reversed | yields thick and thin
left hook | yields thick and thin
left hook reversed | yields thick and thin
right hook | yields thick and thin
right hook reversed | yields thick and thin

##### 14.1.6 Line Caps

round cap | yields for line width 1ex
butt cap | yields for line width 1ex
triangle 90 cap | yields for line width 1ex
triangle 90 cap reversed | yields for line width 1ex
fast cap | yields for line width 1ex
fast cap reversed | yields for line width 1ex

#### 14.2 Snake Library

\usepackage{pgflibrarysnakes} % L A T E X
\input pgflibrarysnakes.tex % plain T E X
\input pgflibrarysnakes.tex % Con T E X t

  This library package defines basic snakes. Section 9.2.3 explains how snakes are used in TikZ, Section 22 explains how new snakes can be defined.

  The snakes are influenced by the current values of parameters like \pgfsnakesegmentamplitude. Only this parameter and \pgfsnakesegmentlength are proper TEX dimensions, all other parameters are TEX macros.

  In TikZ, each parameter can be set using an option having the parameters name minus the \pgfsnake part.

Snake border

  This snake adds straight lines the path that are at a specific angle to the line toward the target. The idea is to add these little lines to indicate the “border” or an area. The following parameters influence the snake:

  - \pgfsnakesegmentlength determines the distance between consecutive ticks.
  - \pgfsnakesegmentamplitude determines the length of the ticks.
  - \pgfsnakesegmentangle determines the angle between the ticks and the line toward the target.

  \tikz{\draw (0,0) rectangle (3,1) [snake=border,segment angle=-45] (0,0) rectangle (3,1);}

Snake brace

  This snake adds a long brace to the path. The left and right end of the brace will be exactly on the start and endpoint of the snake. The following parameters influence the snake:

  - \pgfsnakesegmentamplitude determines how much the brace rises above the path.
  - \pgfsnakesegmentaspect determines the fraction of the total length where the “middle part” of the brace will be.

  \tikz{\draw[snake=brace,segment aspect=0.25] (0,0) -- (3,0);}

Snake bumps

  This snake consists of little half ellipses. The following parameters influence the snake:

  - \pgfsnakesegmentamplitude determines the height of the half ellipse.
  - \pgfsnakesegmentlength determines the width of the half ellipse.

  \tikz{\draw[snake=bumps] (0,0) -- (3,0);}

Snake coil

  This snake adds a coil to the path. To understand how this works, imagine a three-dimensional spring. The spring’s axis points along the line toward the target. Then, we “view” the spring from a certain angle. If we look “straight from the side” we will see a perfect sine curve, if we look “more from the front” we will see a coil. The following parameters influence the snake:

  - \pgfsnakesegmentamplitude determines how much the coil rises above the path and falls below it. Thus, this is the radius of the coil.
  - \pgfsnakesegmentlength determines the distance between two consecutive “curls.” Thus, when the spring is see “from the side” this will be the wave length of the sine curve.
  - \pgfsnakesegmentaspect determines the “viewing direction.” A value of 0 means “looking from the side” and a value of 0.5, which is the default, means “look more from the front.”

  \begin{tikzpicture}[segment amplitude=10pt] \draw[snake=coil] (0,1) -- (3,1); \draw[snake=coil,segment aspect=0] (0,0) -- (3,0); \end{tikzpicture}

Snake expanding waves

  This snake adds arcs to the path that get bigger along the line towards the target. The following parameters influence the snake:

  - \pgfsnakesegmentlength determines the distance between consecutive arcs.
  - \pgfsnakesegmentangle determines the opening angle below and above the path. Thus, the total opening angle is twice this angle.

  \tikz{\draw[snake=expanding waves] (0,0) -- (3,0);}

Snake saw

  This snake looks like the blade of a saw. The following parameters influence the snake:

  - \pgfsnakesegmentamplitude determines how much each spike raises above the straight line.
  - \pgfsnakesegmentlength determines the length each spike.

  \tikz{\draw[snake=saw] (0,0) -- (3,0);}

Snake snake

  This snake is the “architypical” snake: It looks like a snake seen from above. More precisely, the snake is a sine wave with a “softened” start and ending. The following parameters influence the snake:

  - \pgfsnakesegmentamplitude determines the sine wave’s amplitude.
  - \pgfsnakesegmentlength determines the sine wave’s wave length.

  \tikz{\draw[snake=snake] (0,0) -- (3,0);}

Snake ticks

  This snake adds straight lines the path that are orthogonal to the line toward the target. The following parameters influence the snake:

  - \pgfsnakesegmentlength determines the distance between consecutive ticks.
  - \pgfsnakesegmentamplitude determines half the length of the ticks.

  \tikz{\draw[snake=ticks] (0,0) -- (3,0);}

Snake triangles

  This snake adds triangles to the path that point toward the target. The following parameters influence the snake:

  - \pgfsnakesegmentlength determines the distance between consecutive triangles.
  - \pgfsnakesegmentamplitude determines half the length of the triangle side that is orthogonal to the path.
  - \pgfsnakesegmentobjectlength determines the height of the triangle.

  \tikz{\draw[snake=triangles] (0,0) -- (3,0);}

Snake waves

  This snake adds arcs to the path that have a constant size. The following parameters influence the snake:

  - \pgfsnakesegmentlength determines the distance between consecutive arcs.
  - \pgfsnakesegmentangle determines the opening angle below and above the path. Thus, the total opening angle is twice this angle.
  - \pgfsnakesegmentamplitude determines the radius of each arc.

  \tikz{\draw[snake=waves] (0,0) -- (3,0);}

Snake zigzag

  This snake looks like a zig-zag line. The following parameters influence the snake:

  - \pgfsnakesegmentamplitude determines how much the zig-zag lines raises above and falls below a straight line to the target point.
  - \pgfsnakesegmentlength determines the length of a complete “up-down” cycle.

  \tikz{\draw[snake=zigzag] (0,0) -- (3,0);}

#### 14.3 Plot Handler Library

\usepackage{pgflibraryplothandlers} % L A T E X
\input pgflibraryplothandlers.tex % plain T E X
\input pgflibraryplothandlers.tex % Con T E X t

  This library packages defines additional plot handlers, see Section 29.3 for an introduction to plot handlers. The additional handlers are described in the following.

##### 14.3.1 Curve Plot Handlers

\pgfplothandlercurveto

  This handler will issue a \pgfpathcurveto command for each point of the plot, except possibly for the first. As for the line-to handler, what happens with the first point can be specified using \pgfsetmovetofirstplotpoint or \pgfsetlinetofirstplotpoint.

  Obviously, the \pgfpathcurveto command needs, in addition to the points on the path, some control points. These are generated automatically using a somewhat “dumb” algorithm: Suppose you have three points x, y, and z on the curve such that y is between x and z:

  \begin{tikzpicture} \draw[gray] (0,0) node {x} (1,1) node {y} (2,.5) node {z}; \pgfplothandlercurveto \pgfplotstreamstart \pgfplotstreampoint{\pgfpoint{0cm}{0cm}} \pgfplotstreampoint{\pgfpoint{1cm}{1cm}} \pgfplotstreampoint{\pgfpoint{2cm}{.5cm}} \pgfplotstreamend \pgfusepath{stroke} \end{tikzpicture}

  In order to determine the control points of the curve at the point y, the handler computes the vector z - x and scales it by the tension factor (see below). Let us call the resulting vector s. Then y + s and y - s will be the control points around y. The first control point at the beginning of the curve will be the beginning itself, once more; likewise the last control point is the end itself.

\pgfsetplottension{<value>}

  Sets the factor used by the curve plot handlers to determine the distance of the control points from the points they control. The higher the curvature of the curve points, the higher this value should be. A value of 1 will cause four points at quarter positions of a circle to be connected using a circle. The default is 0.5.

  \begin{tikzpicture} \draw[gray] (0,0) node {x} (1,1) node {y} (2,.5) node {z}; \pgfsetplottension{0.75} \pgfplothandlercurveto \pgfplotstreamstart \pgfplotstreampoint{\pgfpoint{0cm}{0cm}} \pgfplotstreampoint{\pgfpoint{1cm}{1cm}} \pgfplotstreampoint{\pgfpoint{2cm}{0.5cm}} \pgfplotstreamend \pgfusepath{stroke} \end{tikzpicture}

\pgfplothandlerclosedcurve

  This handler works like the curve-to plot handler, only it will add a new part to the current path that is a closed curve through the plot points.

  \begin{tikzpicture} \draw[gray] (0,0) node {x} (1,1) node {y} (2,.5) node {z}; \pgfplothandlerclosedcurve \pgfplotstreamstart \pgfplotstreampoint{\pgfpoint{0cm}{0cm}} \pgfplotstreampoint{\pgfpoint{1cm}{1cm}} \pgfplotstreampoint{\pgfpoint{2cm}{0.5cm}} \pgfplotstreamend \pgfusepath{stroke} \end{tikzpicture}

##### 14.3.2 Comb Plot Handlers

There are three “comb” plot handlers. There name stems from the fact that the plots they produce look like “combs” (more or less).

\pgfplothandlerxcomb

  This handler converts each point in the plot stream into a line from the y-axis to the point’s coordinate, resulting in a “horizontal comb.”

  \begin{tikzpicture} \draw[gray] (0,0) node {x} (1,1) node {y} (2,.5) node {z}; \pgfplothandlerxcomb \pgfplotstreamstart \pgfplotstreampoint{\pgfpoint{0cm}{0cm}} \pgfplotstreampoint{\pgfpoint{1cm}{1cm}} \pgfplotstreampoint{\pgfpoint{2cm}{0.5cm}} \pgfplotstreamend \pgfusepath{stroke} \end{tikzpicture}

\pgfplothandlerycomb

  This handler converts each point in the plot stream into a line from the x-axis to the point’s coordinate, resulting in a “vertical comb.”

  This handler is useful for creating “bar diagrams.”

  \begin{tikzpicture} \draw[gray] (0,0) node {x} (1,1) node {y} (2,.5) node {z}; \pgfplothandlerycomb \pgfplotstreamstart \pgfplotstreampoint{\pgfpoint{0cm}{0cm}} \pgfplotstreampoint{\pgfpoint{1cm}{1cm}} \pgfplotstreampoint{\pgfpoint{2cm}{0.5cm}} \pgfplotstreamend \pgfusepath{stroke} \end{tikzpicture}

\pgfplothandlerpolarcomb

  This handler converts each point in the plot stream into a line from the origin to the point’s coordinate.

  \begin{tikzpicture} \draw[gray] (0,0) node {x} (1,1) node {y} (2,.5) node {z}; \pgfplothandlerpolarcomb \pgfplotstreamstart \pgfplotstreampoint{\pgfpoint{0cm}{0cm}} \pgfplotstreampoint{\pgfpoint{1cm}{1cm}} \pgfplotstreampoint{\pgfpoint{2cm}{0.5cm}} \pgfplotstreamend \pgfusepath{stroke} \end{tikzpicture}

##### 14.3.3 Mark Plot Handler

\pgfplothandlermark{<mark code>}

  This command will execute the <mark code> for each point of the plot, but each time the coordinate transformation matrix will be setup such that the origin is at the position of the point to be plotted. This way, if the <mark code> draws a little circle around the origin, little circles will be drawn at each point of the plot.

  \begin{tikzpicture} \draw[gray] (0,0) node {x} (1,1) node {y} (2,.5) node {z}; \pgfplothandlermark{\pgfpathcircle{\pgfpointorigin}{4pt}\pgfusepath{stroke}} \pgfplotstreamstart \pgfplotstreampoint{\pgfpoint{0cm}{0cm}} \pgfplotstreampoint{\pgfpoint{1cm}{1cm}} \pgfplotstreampoint{\pgfpoint{2cm}{0.5cm}} \pgfplotstreamend \pgfusepath{stroke} \end{tikzpicture}

  Typically, the <code> will be \pgfuseplotmark{<plot mark name>}, where <plot mark name> is the name of a predefined plot mark.

\pgfuseplotmark{<plot mark name>}

  Draws the given <plot mark name> at the origin. The <plot mark name> must previously have been declared using \pgfdeclareplotmark.

  \begin{tikzpicture} \draw[gray] (0,0) node {x} (1,1) node {y} (2,.5) node {z}; \pgfplothandlermark{\pgfuseplotmark{pentagon}} \pgfplotstreamstart \pgfplotstreampoint{\pgfpoint{0cm}{0cm}} \pgfplotstreampoint{\pgfpoint{1cm}{1cm}} \pgfplotstreampoint{\pgfpoint{2cm}{0.5cm}} \pgfplotstreamend \pgfusepath{stroke} \end{tikzpicture}

\pgfdeclareplotmark{<plot mark name>}{<code>}

  Declares a plot mark for later used with the \pgfuseplotmark command.

  \pgfdeclareplotmark{my plot mark} {\pgfpathcircle{\pgfpoint{0cm}{1ex}}{1ex}\pgfusepathqstroke} \begin{tikzpicture} \draw[gray] (0,0) node {x} (1,1) node {y} (2,.5) node {z}; \pgfplothandlermark{\pgfuseplotmark{my plot mark}} \pgfplotstreamstart \pgfplotstreampoint{\pgfpoint{0cm}{0cm}} \pgfplotstreampoint{\pgfpoint{1cm}{1cm}} \pgfplotstreampoint{\pgfpoint{2cm}{0.5cm}} \pgfplotstreamend \pgfusepath{stroke} \end{tikzpicture}

\pgfsetplotmarksize{<dimension>}

  This command sets the TEX dimension \pgfplotmarksize to <dimension>. This dimension is a “recommendation” for plot mark code at which size the plot mark should be drawn; plot mark code may choose to ignore this <dimension> altogether. For circles, <dimension> should be the radius, for other shapes it should be about half the width/height.

  The predefined plot marks all take this dimension into account.

  \begin{tikzpicture} \draw[gray] (0,0) node {x} (1,1) node {y} (2,.5) node {z}; \pgfsetplotmarksize{1ex} \pgfplothandlermark{\pgfuseplotmark{*}} \pgfplotstreamstart \pgfplotstreampoint{\pgfpoint{0cm}{0cm}} \pgfplotstreampoint{\pgfpoint{1cm}{1cm}} \pgfplotstreampoint{\pgfpoint{2cm}{0.5cm}} \pgfplotstreamend \pgfusepath{stroke} \end{tikzpicture}

\pgfplotmarksize

  A TEX dimension that is a “recommendation” for the size of plot marks.

The following plot marks are predefined (the filling color has been set to yellow):

\pgfuseplotmark{*} |
\pgfuseplotmark{x} |
\pgfuseplotmark{+} |

#### 14.4 Plot Mark Library

\usepackage{pgflibraryplotmarks} % L A T E X
\input pgflibraryplotmarks.tex % plain T E X
\input pgflibraryplotmarks.tex % Con T E X t

  When this package is loaded, the following plot marks are defined in addition to *, x, and + (the filling color has been set to a dark yellow):

  \pgfuseplotmark{-} |
  \pgfuseplotmark{|} |
  \pgfuseplotmark{o} |
  \pgfuseplotmark{asterisk} |
  \pgfuseplotmark{star} |
  \pgfuseplotmark{oplus} |
  \pgfuseplotmark{oplus*} |
  \pgfuseplotmark{otimes} |
  \pgfuseplotmark{otimes*} |
  \pgfuseplotmark{square} |
  \pgfuseplotmark{square*} |
  \pgfuseplotmark{triangle} |
  \pgfuseplotmark{triangle*} |
  \pgfuseplotmark{diamond} |
  \pgfuseplotmark{diamond*} |
  \pgfuseplotmark{pentagon} |
  \pgfuseplotmark{pentagon*} |

#### 14.5 Shape Library

\usepackage{pgflibraryshapes} % L A T E X
\input pgflibraryshapes.tex % plain T E X
\input pgflibraryshapes.tex % Con T E X t

  This library packages defines additional shapes, which are described in the following.

Shape cross out

  This shape “crosses out” the node. Its foreground path are simply two diagonal lines that between the corners of the node’s bounding box. Here is an example:

  \begin{tikzpicture} \draw[help lines] (0,0) grid (3,2); \node [cross out,draw=red] at (1.5,1) {cross out}; \end{tikzpicture}

  A useful application is inside text as in the following example:

  Cross out! |
  Cross \tikz[baseline] \node [cross out,draw,anchor=text] {me}; out!

  This shape inherits all anchors from the rectangle shape, see also the following figure:

  \Huge \begin{tikzpicture} \node[name=s,shape=cross out,style=shape example] {cross out\vrule width 1pt height 2cm}; \foreach \anchor/\placement in {north west/above left, north/above, north east/above right, west/left, center/above, east/right, mid west/right, mid/above, mid east/left, base west/left, base/below, base east/right, south west/below left, south/below, south east/below right, text/left, 10/right, 130/above} \draw[shift=(s.\anchor)] plot[mark=x] coordinates{(0,0)} node[\placement] {\scriptsize\texttt{(s.\anchor)}}; \end{tikzpicture}

Shape ellipse

  This shape is an ellipse tightly fitting the text box, if no inner separation is given. The following figure shows the anchors this shape defines; the anchors 10 and 130 are example of border anchors.

  \Huge \begin{tikzpicture} \node[name=s,shape=ellipse,style=shape example] {Ellipse\vrule width 1pt height 2cm}; \foreach \anchor/\placement in {north west/above left, north/above, north east/above right, west/left, center/above, east/right, mid west/right, mid/above, mid east/left, base west/left, base/below, base east/right, south west/below left, south/below, south east/below right, text/left, 10/right, 130/above} \draw[shift=(s.\anchor)] plot[mark=x] coordinates{(0,0)} node[\placement] {\scriptsize\texttt{(s.\anchor)}}; \end{tikzpicture}

Shape forbidden sign

  This shape places the node inside a circle with a diagonal from the lower left to the upper right added. The circle is part of the background, the diagonal line part of the foreground path; thus, the diagonal line is on top of the text.

  \begin{tikzpicture} \node [forbidden sign,line width=1ex,draw=red,fill=white] {Smoking}; \end{tikzpicture}

  The shape inherits all anchors from the circle shape, see also the following figure:

  \Huge \begin{tikzpicture} \node[name=s,shape=forbidden sign,style=shape example] {Forbidden\vrule width 1pt height 2cm}; \foreach \anchor/\placement in {north west/above left, north/above, north east/above right, west/left, center/above, east/right, mid west/right, mid/above, mid east/left, base west/left, base/below, base east/right, south west/below left, south/below, south east/below right, text/left, 10/right, 130/above} \draw[shift=(s.\anchor)] plot[mark=x] coordinates{(0,0)} node[\placement] {\scriptsize\texttt{(s.\anchor)}}; \end{tikzpicture}

Shape strike out

  This shape is idential to the cross out shape, only its foreground path consists of a single line from the lower left to the upper right.

  Strike out! |
  Strike \tikz[baseline] \node [strike out,draw,anchor=text] {me}; out!

  See the cross out shape for the anchors.

#### 14.6 Tree Library

\usepackage{pgflibrarytikztrees} % L A T E X
\input pgflibrarytikztrees.tex % plain T E X
\input pgflibrarytikztrees.tex % Con T E X t

  This packages defines styles to be used when drawing trees.

##### 14.6.1 Growth Functions

The package pgflibrarytikztrees defines two new growth functions. They are installed using the following options:

- grow via three points=one child at (<x>) and two children at (<y>) and (<z>) This option installs a growth function that works as follows: If a parent node has just one child, this child is placed at <x>. If the parent node has two children, these are placed at <y> and <z>. If the parent node has more than two children, the children are placed at points that are linearly extrapolated from the three points <x>, <y>, and <z>. In detail, the position is x+(y-x)+(c-1)(z-y), where n is the number of children and c is the number of the current child (starting with 1).

  The net effect of all this is that if you have a certain “linear arrangement” in mind and use this option to specify the placement of a single child and of two children, then any number of children will be placed correctly.

  Here are some arrangements based on this growth function. We start with a simple “above” arrangement:

  \begin{tikzpicture}[grow via three points={% one child at (0,1) and two children at (-.5,1) and (.5,1)}] \node at (0,0) {one} child; \node at (0,-1.5) {two} child child; \node at (0,-3) {three} child child child; \node at (0,-4.5) {four} child child child child; \end{tikzpicture}

  The next arrangement places children above, but “grows only to the right.”

  \begin{tikzpicture}[grow via three points={% one child at (0,1) and two children at (0,1) and (1,1)}] \node at (0,0) {one} child; \node at (0,-1.5) {two} child child; \node at (0,-3) {three} child child child; \node at (0,-4.5) {four} child child child child; \end{tikzpicture}

  In the final arrangement, the children are placed along a line going down and right.

  \begin{tikzpicture}[grow via three points={% one child at (-1,-.5) and two children at (-1,-.5) and (0,-.75)}] \node at (0,0) {one} child; \node at (0,-1.5) {two} child child; \node at (0,-3) {three} child child child; \node at (0,-4.5) {four} child child child child; \end{tikzpicture}

  These examples should make it clear how you can create new styles to arrange your children along a line.

- style=grow cyclic This style causes the children to be arranged “on a circle.” For this, the children are placed at distance \tikzleveldistance from the parent node, but not on a straight line, but points on a circle. Instead of a sibling distance, there is a sibling angle that denotes the angle between two given children.
  - sibling angle=<angle> Sets the angle between siblings in the grow cyclic style.

  Note that this function will rotate the coordinate system of the children to ensure that the grandchildren will grow in the right direction.

  \begin{tikzpicture}[grow cyclic] \tikzstyle{level 1}=[level distance=8mm,sibling angle=60] \tikzstyle{level 2}=[level distance=4mm,sibling angle=45] \tikzstyle{level 3}=[level distance=2mm,sibling angle=30] \coordinate [rotate=-90] % going down child foreach \x in {1,2,3} {child foreach \x in {1,2,3} {child foreach \x in {1,2,3}}}; \end{tikzpicture}

##### 14.6.2 Edges From Parent

The following styles can be used to modify how the edges from parents are drawn:

- style=edge from parent fork down This style will draw a line from the parent downwards (for half the level distance) and then on to the child using only horizontal and vertical lines.

  \begin{tikzpicture} \node {root} [edge from parent fork down] child {node {left}} child {node {right} child[child anchor=north east] {node {child}} child {node {child}} }; \end{tikzpicture}

- style=edge from parent fork right This style behaves similarly, only it will first draw its edge to the right.

  \begin{tikzpicture} \node {root} [edge from parent fork right,grow=right] child {node {left}} child {node {right} child {node {child}} child {node {child}} }; \end{tikzpicture}

- style=edge from parent fork left behaves similary.
- style=edge from parent fork up behaves similary.

#### 14.7 Background Library

\usepackage{pgflibrarytikzbackgrounds} % L A T E X
\input pgflibrarytikzbackgrounds.tex % plain T E X
\input pgflibrarytikzbackgrounds.tex % Con T E X t

  This packages defines “backgrounds” for pictures. This does not refer to background pictures, but rather to frames drawn around and behind pictures. For example, this package allows you to just add the framed option to a picture to get a rectangular box around your picture or gridded to put a grid behind your picture.

When this package is loaded, the following styles become available:

- style=show background rectangle This style causes a rectangle to be drawn behind your graphic. This style option must be given to the {tikzpicture} environment or to the \tikz command.

  \begin{tikzpicture}[show background rectangle] \draw (0,0) ellipse (10mm and 5mm); \end{tikzpicture}

  The size of the background rectangle is determined as follows: We start with the bounding box of the picture. Then, a certain separator distance is added on the sides. This distance can be different for the x- and y-directions and can be set using the following options:

  - inner frame xsep=<dimension> Sets the additional horizontal separator distance for the background rectangle. The default is 1ex.
  - inner frame ysep=<dimension> Same for the vertical separator distance.
  - inner frame sep=<dimension> sets the horizontal and vertical separator distances simultaneously.

  The following two styles make setting the inner separator a bit easier to remember:

  - style=tight background Sets the inner frame separator to 0pt. The background rectangle will have the size of the bounding box.
  - style=loose background Sets the inner frame separator to 2ex.

  You can influence how the background rectangle is rendered by setting the following style:

  - style=background rectangle This style dictates how the background rectangle is drawn or filled. By default this style is set to draw, which causes the path of the background rectangle to be drawn in the usual way. Setting this style to, say, fill=blue!20 causes a light blue background to be added to the picture. You can also use more fancy settings as shown in the following example:

    \tikzstyle{background rectangle}= [double,ultra thick,draw=red,top color=blue,rounded corners] \begin{tikzpicture}[show background rectangle] \draw (0,0) ellipse (10mm and 5mm); \end{tikzpicture}

    Naturally, no one in their right mind would use the above, but here is a nice background:

    \tikzstyle{background rectangle}= [draw=blue!50,fill=blue!20,rounded corners=1ex] \begin{tikzpicture}[show background rectangle] \draw (0,0) ellipse (10mm and 5mm); \end{tikzpicture}

- style=framed This is a shorthand for show background rectangle.
- style=show background grid This style behaves similarly to the show background rectangle style, but it will not use a rectangle path, but a grid. The lower left and upper right corner of the grid is computed in the same way as for the background rectangle:

  \begin{tikzpicture}[show background grid] \draw (0,0) ellipse (10mm and 5mm); \end{tikzpicture}

  You can influence the background grid by setting the following style:

  - style=background grid This style dictates how the background grid path is drawn. The default is draw,help lines.

    \tikzstyle{background grid}=[thick,draw=red,step=.5cm] \begin{tikzpicture}[show background grid] \draw (0,0) ellipse (10mm and 5mm); \end{tikzpicture}

    This option can be combined with the framed option (use the framed option first):

    \tikzstyle{background grid}=[thick,draw=red,step=.5cm] \tikzstyle{background rectangle}=[rounded corners,fill=yellow] \begin{tikzpicture}[framed,gridded] \draw (0,0) ellipse (10mm and 5mm); \end{tikzpicture}

  - style=gridded This is a shorthand for show background grid.
- style=show background top This style causes a single line to be drawn at the top of the background rectangle. Normally, the line coincides exactly with the top line of the background rectangle:

  \tikzstyle{background rectangle}=[fill=yellow] \begin{tikzpicture}[framed,show background top] \draw (0,0) ellipse (10mm and 5mm); \end{tikzpicture}

  The following option allows you to lengthen (or shorten) the line:

  - outer frame xsep=<dimension> The <dimension> is added at the left and right side of the line.

    \tikzstyle{background rectangle}=[fill=yellow] \begin{tikzpicture} [framed,show background top,outer frame xsep=1ex] \draw (0,0) ellipse (10mm and 5mm); \end{tikzpicture}

  - outer frame ysep=<dimension> This option does not apply to the top line, but to the left and right lines, see below.
  - outer frame sep=<dimension> Sets both the x- and y-separation.

    \tikzstyle{background rectangle}=[fill=blue!20] \begin{tikzpicture} [outer frame sep=1ex,% show background top,% show background bottom,% show background left,% show background right] \draw (0,0) ellipse (10mm and 5mm); \end{tikzpicture}

  You can influence how the line is drawn grid by setting the following style:

  - style=background top Default is draw.

    \tikzstyle{background rectangle}=[fill=blue!20] \tikzstyle{background top}=[draw=blue!50,line width=1ex] \begin{tikzpicture}[framed,show background top] \draw (0,0) ellipse (10mm and 5mm); \end{tikzpicture}

- style=show background bottom works like the style for the top line.
- style=show background left works like the style for the top line.
- style=show background right works like the style for the top line.

#### 14.8 Automata Drawing Library

\usepackage{pgflibraryautomata} % L A T E X
\input pgflibraryautomata.tex % plain T E X
\input pgflibraryautomata.tex % Con T E X t

  This packages, which is still under construction, provides shapes and styles for drawing automata.

Shape state

  This shape is currently just an alias for the circle shape. However, it is useful to have another shape state since one can then say, for example, the the style every state shape should be set to some special value.

Shape state with output

  This shape is a multi-part shape. The main part (the text part) is the name of the state as in the state shape. The second part is called output. This node part is drawn in the lower part of the node, separated from the upper part by a line.

  \begin{tikzpicture} \node [state with output,draw,double,fill=red!20] { $q_1$ \nodepart{output} $00$ }; \end{tikzpicture}

  The shape inherits all anchors from the circle shape and defines the output anchor in addition. See also the following figure:

  \Huge \begin{tikzpicture} \node[name=s,shape=state with output,style=shape example] {state name\nodepart{output}output}; \foreach \anchor/\placement in {north west/above left, north/above, north east/above right, west/left, center/below, east/right, mid west/right, mid/above, mid east/left, base west/left, base/below, base east/right, south west/below left, south/below, south east/below right, text/left, output/left, 130/above} \draw[shift=(s.\anchor)] plot[mark=x] coordinates{(0,0)} node[\placement] {\scriptsize\texttt{(s.\anchor)}}; \end{tikzpicture}

[next] [front] [up]