[next] [prev] [prev-tail] [tail] [up]

### 10 Actions on Paths

Once a path has been constructed, different things can be done with it. It can be drawn (or stroked) with a “pen,” it can be filled with a color or shading, it can be used for clipping subsequent drawing, it can be used to specify the extend of the picture--or any combination of these actions at the same time.

To decide what is to be done with a path, two methods can be used. First, you can use a special-purpose command like \draw to indicate that the path should be drawn. However, commands like \draw and \fill are just abbreviations for special cases of the more general method: Here, the \path command is used to specify the path. Then, options encountered on the path indicate what should be done with the path.

For example, \path (0,0) circle (1cm); means “This is a path consisting of a circle around the origin. Do not do anything with it (throw it away).” However, if the option draw is encountered anywhere on the path, the circle will be drawn. “Anywhere” is any point on the path where an option can be given, which is everywhere where a path command like circle (1cm) or rectangle (1,1) or even just (0,0) would also be allowed. Thus, the following commands all draw the same circle:

\path [draw] (0,0) circle (1cm); \path (0,0) [draw] circle (1cm); \path (0,0) circle (1cm) [draw];

Finally, \draw (0,0) circle (1cm); also draws a path, because \draw is an abbreviation for \path [draw] and thus the command expands to the first line of the above example.

Similarly, \fill is an abbreviation for \path[fill] and \filldraw is an abbreviation for the command \path[fill,draw]. Since options accumulate, the following commands all have the same effect:

\path [draw,fill] (0,0) circle (1cm); \path [draw] [fill] (0,0) circle (1cm); \path [fill] (0,0) circle (1cm) [draw]; \draw [fill] (0,0) circle (1cm); \fill (0,0) [draw] circle (1cm); \filldraw (0,0) circle (1cm);

In the following subsection the different actions are explained that can be performed on a path. The following commands are abbreviations for certain sets of actions, but for many useful combinations there are no abbreviations:

\draw

  Inside {tikzpicture} this is an abbreviation for \path[draw].

\fill

  Inside {tikzpicture} this is an abbreviation for \path[fill].

\filldraw

  Inside {tikzpicture} this is an abbreviation for \path[fill,draw].

\shade

  Inside {tikzpicture} this is an abbreviation for \path[shade].

\shadedraw

  Inside {tikzpicture} this is an abbreviation for \path[shade,draw].

\clip

  Inside {tikzpicture} this is an abbreviation for \path[clip].

\useasboundingbox

  Inside {tikzpicture} this is an abbreviation for \path[use as bounding box].

\node

  Inside {tikzpicture} this is an abbreviation for \path node. Note that, for once, node is not an option but a path operation.

\coordinate

  Inside {tikzpicture} this is an abbreviation for \path coordinate.

#### 10.1 Specifying a Color

The most unspecific option for setting colors is the following:

- color=<color name>This option sets the color that is used for fill, drawing, and text inside the current scope. Any special settings for filling colors or drawing colors are immediately “overruled” by this option.

  The <color name> is the name of a previously defined color. For LATEX users, this is just a normal “LATEX-color” and the xcolor extensions are allows. Here is an example:

  \tikz \fill[color=red!20] (0,0) circle (1ex);

  It is possible to “leave out” the color= part and you can also write:

  \tikz \fill[red!20] (0,0) circle (1ex);

  What happens is that every option that TikZ does not know, like red!20, gets a “second chance” as a color name.

  For plain TEX users, it is not so easy to specify colors since plain TEX has no “standardized” color naming mechanism. Because of this, PGF emulates the xcolor package, though the emulation is extremely basic (more precisely, what I could hack together in two hours or so). The emulation allows you to do the following:

  - Specify a new color using \definecolor. Only the two color models gray and rgb are supported.

    Example: \definecolor{orange}{rgb}{1,0.5,0}

  - Use \colorlet to define a new color based on an old one. Here, the ! mechanism is supported, though only “once” (use multiple \colorlet for more fancy colors).

    Example: \colorlet{lightgray}{black!25}

  - Use \color{<color name>} to set the color in the current TEX group. \aftergroup-hackery is used to restore the color after the group.

As pointed out above, the color= option applies to “everything” (except to shadings), which is not always what you want. Because of this, there are several more specialized color options. For example, the draw= option sets the color used for drawing, but does not modify the color used for filling. These color options are documented where the path action they influence is described.

#### 10.2 Drawing a Path

You can draw a path using the following option:

- draw=<color> Causes the path to be drawn. “Drawing” (also known as “stroking”) can be thought of as picking up a pen and moving it along the path, thereby leaving “ink” on the canvas.

  There are numerous parameters that influence how a line is drawn, like the thickness or the dash pattern. These options are explained below.

  If the optional <color> argument is given, drawing is done using the given <color>. This color can be different from the current filling color, which allows you to draw and fill a path with different colors. If no <color> argument is given, the last usage of the color= option is used.

  If the special color name none is given, this option causes drawing to be “switched off.” This is useful if a style has previously switched on drawing and you locally wish to undo this effect.

  Although this option is normally used on paths to indicate that the path should be drawn, it also makes sense to use the option with a {scope} or {tikzpicture} environment. However, this will not cause all path to drawn. Instead, this just sets the <color> to be used for drawing paths inside the environment.

  \begin{tikzpicture} \path[draw=red] (0,0) -- (1,1) -- (2,1) circle (10pt); \end{tikzpicture}

The following subsections list the different options that influence how a path is drawn. All of these options only have an effect if the draw options is given (directly or indirectly).

##### 10.2.1 Graphic Parameters: Line Width, Line Cap, and Line Join

- line width=<dimension> Specifies the line width. Note the space. Default: 0.4pt.

  \tikz \draw[line width=5pt] (0,0) -- (1cm,1.5ex);

There are a number of predefined styles that provide more “natural” ways of setting the line width. You can also redefine these styles. Remember that you can leave out the style= when setting a style.

- style=ultra thin Sets the line width to 0.1pt.

  \tikz \draw[ultra thin] (0,0) -- (1cm,1.5ex);

- style=very thin Sets the line width to 0.2pt.

  \tikz \draw[very thin] (0,0) -- (1cm,1.5ex);

- style=thin Sets the line width to 0.4pt.

  \tikz \draw[thin] (0,0) -- (1cm,1.5ex);

- style=semithick Sets the line width to 0.6pt.

  \tikz \draw[semithick] (0,0) -- (1cm,1.5ex);

- style=thick Sets the line width to 0.8pt.

  \tikz \draw[thick] (0,0) -- (1cm,1.5ex);

- style=very thick Sets the line width to 1.2pt.

  \tikz \draw[very thick] (0,0) -- (1cm,1.5ex);

- style=ultra thick Sets the line width to 1.6pt.

  \tikz \draw[ultra thick] (0,0) -- (1cm,1.5ex);

- cap=<type> Specifies how lines “end.” Permissible <type> are round, rect, and butt (default). They have the following effects:

  \begin{tikzpicture} \begin{scope}[line width=10pt] \draw[cap=rect] (0,0 ) -- (1,0); \draw[cap=butt] (0,.5) -- (1,.5); \draw[cap=round] (0,1 ) -- (1,1); \end{scope} \draw[white,line width=1pt] (0,0 ) -- (1,0) (0,.5) -- (1,.5) (0,1 ) -- (1,1); \end{tikzpicture}

- join=<type> Specifies how lines “join.” Permissible <type> are round, bevel, and miter (default). They have the following effects:

  \begin{tikzpicture}[line width=10pt] \draw[join=round] (0,0) -- ++(.5,1) -- ++(.5,-1); \draw[join=bevel] (1.25,0) -- ++(.5,1) -- ++(.5,-1); \draw[join=miter] (2.5,0) -- ++(.5,1) -- ++(.5,-1); \useasboundingbox (0,1.5); % make bounding box bigger \end{tikzpicture}

- miter limit=<factor> When you use the miter join and there is a very sharp corner (a small angle), the miter join may protrude very far over the actual joining point. In this case, if it were to protrude by more than <factor> times the line width, the miter join is replaced by a bevel join. Default value is 10.

  \begin{tikzpicture}[line width=5pt] \draw (0,0) -- ++(5,.5) -- ++(-5,.5); \draw[miter limit=25] (6,0) -- ++(5,.5) -- ++(-5,.5); \useasboundingbox (14,0); % make bounding box bigger \end{tikzpicture}

##### 10.2.2 Graphic Parameters: Dash Pattern

- dash pattern=<dash pattern> Sets the dashing pattern. The syntax is the same as in METAFONT. For example on 2pt off 3pt on 4pt off 4pt means “draw 2pt, then leave out 3pt, then draw 4pt once more, then leave out 4pt again, repeat”.

  \begin{tikzpicture}[dash pattern=on 2pt off 3pt on 4pt off 4pt] \draw (0pt,0pt) -- (3.5cm,0pt); \end{tikzpicture}

- dash phase=<dash phase> Shifts the start of the dash pattern by <phase>.

  \begin{tikzpicture}[dash pattern=on 20pt off 10pt] \draw[dash phase=0pt] (0pt,3pt) -- (3.5cm,3pt); \draw[dash phase=10pt] (0pt,0pt) -- (3.5cm,0pt); \end{tikzpicture}

As for the line thickness, some predefined styles allow you to set the dashing conveniently.

- style=solid Shorthand for setting a solid line as “dash pattern.” This is the default.

  \tikz \draw[solid] (0pt,0pt) -- (50pt,0pt);

- style=dotted Shorthand for setting a dotted dash pattern.

  \tikz \draw[dotted] (0pt,0pt) -- (50pt,0pt);

- style=densely dotted Shorthand for setting a densely dotted dash pattern.

  \tikz \draw[densely dotted] (0pt,0pt) -- (50pt,0pt);

- style=loosely dotted Shorthand for setting a loosely dotted dash pattern.

  \tikz \draw[loosely dotted] (0pt,0pt) -- (50pt,0pt);

- style=dashed Shorthand for setting a dashed dash pattern.

  \tikz \draw[dashed] (0pt,0pt) -- (50pt,0pt);

- style=densely dashed Shorthand for setting a densely dashed dash pattern.

  \tikz \draw[densely dashed] (0pt,0pt) -- (50pt,0pt);

- style=loosely dashed Shorthand for setting a loosely dashed dash pattern.

  \tikz \draw[loosely dashed] (0pt,0pt) -- (50pt,0pt);

##### 10.2.3 Graphic Parameters: Draw Opacity

When a line is drawn, it will normally “obscure” everything behind it as if you has used perfectly opaque ink. It is also possible to ask TikZ to use an ink that is a little bit (or a big bit) transparent. To do so, use the following option:

- draw opacity=<value> This option sets “how transparent” lines should be. A value of 1 means “fully opaque” or “not transparent at all,” a value of 0 means “fully transparent” or “invisible.” A value of 0.5 yields lines that are semitransparent.

  Note that when you use PostScript as your output format, this option works only with recent versions of GhostScript.

  \begin{tikzpicture}[line width=1ex] \draw (0,0) -- (3,1); \filldraw [fill=examplefill,draw opacity=0.5] (1,0) rectangle (2,1); \end{tikzpicture}

Note that the draw opacity options only sets the opacity of drawn lines. The opacity of fillings is set using the option fill opacity (documented in Section 10.3.2. The option opacity sets both at the same time.

- opacity=<value> Sets both the drawing and filling opacity to <value>.

  The following predefined styles make it easier to use this option:

  - style=transparent Makes everything totally transparent and, hence, invisible.

    \tikz{\fill[red] (0,0) rectangle (1,0.5); \fill[transparent,red] (0.5,0) rectangle (1.5,0.25); }

  - style=ultra nearly transparent Makes everything, well, ultra nearly transparent.

    \tikz{\fill[red] (0,0) rectangle (1,0.5); \fill[ultra nearly transparent] (0.5,0) rectangle (1.5,0.25); }

  - style=very nearly transparent

    \tikz{\fill[red] (0,0) rectangle (1,0.5); \fill[very nearly transparent] (0.5,0) rectangle (1.5,0.25); }

  - style=nearly transparent

    \tikz{\fill[red] (0,0) rectangle (1,0.5); \fill[nearly transparent] (0.5,0) rectangle (1.5,0.25); }

  - style=semitransparent

    \tikz{\fill[red] (0,0) rectangle (1,0.5); \fill[semitransparent] (0.5,0) rectangle (1.5,0.25); }

  - style=nearly opaque

    \tikz{\fill[red] (0,0) rectangle (1,0.5); \fill[nearly opaque] (0.5,0) rectangle (1.5,0.25); }

  - style=very nearly opaque

    \tikz{\fill[red] (0,0) rectangle (1,0.5); \fill[very nearly opaque] (0.5,0) rectangle (1.5,0.25); }

  - style=ultra nearly opaque

    \tikz{\fill[red] (0,0) rectangle (1,0.5); \fill[ultra nearly opaque] (0.5,0) rectangle (1.5,0.25); }

  - style=opaque This yields completely opaque drawings, which is the default.

    \tikz{\fill[red] (0,0) rectangle (1,0.5); \fill[opaque] (0.5,0) rectangle (1.5,0.25); }

##### 10.2.4 Graphic Parameters: Arrow Tips

When you draw a line, you can add arrow tips at the ends. It is only possible to add one arrow tip at the start and one at the end. If the path consists of several segments, only the last segment gets arrow tips. The behavior for paths that are closed is not specified and may change in the future.

- arrows=<start arrow kind>-<end arrow kind> This option sets the start and end arrow tips (an empty value as in -> indicates that no arrow tip should be drawn at the start).

  Note: Since the arrow option is so often used, you can leave out the text arrows=. What happens is that every option that contains a - is interpreted as an arrow specification.

  \begin{tikzpicture} \draw[->] (0,0) -- (1,0); \draw[o-stealth] (0,0.3) -- (1,0.3); \end{tikzpicture}

  The permissible values are all predefined arrow tips, though you can also define new arrow tip kinds as explained in Section 24. This is often necessary to obtain “double” arrow tips and arrow tips that have a fixed size. Since pgflibraryarrows is loaded by default, all arrow tips described in Section 14.1 are available.

  One arrow tip kind is special: > (and all arrow tip kinds containing the arrow tip kind such as << or >|). This arrow tip type is not fixed. Rather, you can redefine it using the >= option, see below.

  Example: You can also combine arrow tip types as in

  \begin{tikzpicture}[thick] \draw[to reversed-to] (0,0) .. controls +(.5,0) and +(-.5,-.5) .. +(1.5,1); \draw[[-latex reversed] (1,0) .. controls +(.5,0) and +(-.5,-.5) .. +(1.5,1); \draw[latex-)] (2,0) .. controls +(.5,0) and +(-.5,-.5) .. +(1.5,1); \useasboundingbox (-.1,-.1) rectangle (3.1,1.1); % make bounding box bigger \end{tikzpicture}

- >=<end arrow kind> This option can be used to redefine the “standard” arrow tip >. The idea is that different people have different ideas what arrow tip kind should normally be used. I prefer the arrow tip of TEX’s \to command (which is used in things like f : A B). Other people will prefer LATEX’s standard arrow tip, which looks like this:
  . Since the arrow tip kind > is certainly the most “natural” one to use, it is kept free of any predefined meaning. Instead, you can change it by saying >=to to set the “standard” arrow tip kind to TEX’s arrow tip, whereas >=latex will set it to LATEX’s arrow tip and >=stealth will use a PSTRICKS-like arrow tip.

  Apart from redefining the arrow tip kind > (and < for the start), this option also redefines the following arrow tip kinds: > and < as the swapped version of <end arrow kind>, << and >> as doubled versions, >> and << as swapped doubled versions, and |< and >| as arrow tips ending with a vertical bar.

  \begin{tikzpicture}[scale=2] \begin{scope}[>=latex] \draw[->] (0pt,6ex) -- (1cm,6ex); \draw[>->>] (0pt,5ex) -- (1cm,5ex); \draw[|<->|] (0pt,4ex) -- (1cm,4ex); \end{scope} \begin{scope}[>=diamond] \draw[->] (0pt,2ex) -- (1cm,2ex); \draw[>->>] (0pt,1ex) -- (1cm,1ex); \draw[|<->|] (0pt,0ex) -- (1cm,0ex); \end{scope} \end{tikzpicture}

- shorten >=<dimension> This option will shorten the end of lines by the given <dimension>. If you specify an arrow tip, lines are already shortened a bit such that the arrow tip touches the specified endpoint and does not “protrude over” this point. Here is an example:

  \begin{tikzpicture}[line width=20pt] \useasboundingbox (0,-1.5) rectangle (3.5,1.5); \draw[red] (0,0) -- (3,0); \draw[gray,->] (0,0) -- (3,0); \end{tikzpicture}

  The shorten > option allows you to shorten the end on the line additionally by the given distance. This option can also be useful if you have not specified an arrow tip at all.

  \begin{tikzpicture}[line width=20pt] \useasboundingbox (0,-1.5) rectangle (3.5,1.5); \draw[red] (0,0) -- (3,0); \draw[-to,shorten >=10pt,gray] (0,0) -- (3,0); \end{tikzpicture}

- shorten <=<dimension> works like shorten >, but for the start.

##### 10.2.5 Graphic Parameters: Double Lines and Bordered Lines

- double=<core color> This option causes “two” lines to be drawn instead of a single one. However, this is not what really happens. In reality, the path is drawn twice. First, with the normal drawing color, secondly with the <core color>, which is normally white. Upon the second drawing, the line width is reduced. The net effect is that it appears as if two lines had been drawn and this works well even with complicated, curved paths:

  \tikz \draw[double] plot[smooth cycle] coordinates{(0,0) (1,1) (1,0) (0,1)};

  You can also use the doubling option to create an effect in which a line seems to have a certain “border”:

  \begin{tikzpicture} \draw (0,0) -- (1,1); \draw[draw=white,double=red,very thick] (0,1) -- (1,0); \end{tikzpicture}

- double distance=<dimension> Sets the distance the “two” lines are spaced apart (default is 0.6pt). In reality, this is the thickness of the line that is used to draw the path for the second time. The thickness of the first time the path is drawn is twice the normal line width plus the given <dimension>. As a side-effect, this option “selects” the double option.

  \begin{tikzpicture} \draw[very thick,double] (0,0) arc (180:90:1cm); \draw[very thick,double distance=2pt] (1,0) arc (180:90:1cm); \draw[thin,double distance=2pt] (2,0) arc (180:90:1cm); \end{tikzpicture}

#### 10.3 Filling a Path

To fill a path, use the following option:

- fill=<color> This option causes the path to be filled. All unclosed parts of the path are first closed, if necessary. Then, the area enclosed by the path is filled with the current filling color, which is either the last color set using the general color= option or the optional color <color>. For self-intersection paths and for paths consisting of several closed areas, the “enclosed area” is somewhat complicated to define and two different definitions exist, namely the nonzero winding number rule and the even odd rule, see the explanation of these options, below.

  Just as for the draw option, setting <color> to none disables filling locally.

  \begin{tikzpicture} \fill (0,0) -- (1,1) -- (2,1); \fill (4,0) circle (.5cm) (4.5,0) circle (.5cm); \fill[even odd rule] (6,0) circle (.5cm) (6.5,0) circle (.5cm); \fill (8,0) -- (9,1) -- (10,0) circle (.5cm); \end{tikzpicture}

  If the fill option is used together with the draw option (either because both are given as options or because a \filldraw command is used), the path is filled first, then the path is drawn second. This is especially useful if different colors are selected for drawing and for filling. Even if the same color is used, there is a difference between this command and a plain fill: A “filldrawn” area will be slightly larger than a filled area because of the thickness of the “pen.”

  \begin{tikzpicture}[fill=examplefill,line width=5pt] \filldraw (0,0) -- (1,1) -- (2,1); \filldraw (4,0) circle (.5cm) (4.5,0) circle (.5cm); \filldraw[even odd rule] (6,0) circle (.5cm) (6.5,0) circle (.5cm); \filldraw (8,0) -- (9,1) -- (10,0) circle (.5cm); \end{tikzpicture}

##### 10.3.1 Graphic Parameters: Interior Rules

The following two options can be used to decide how interior points should be determined:

- nonzero rule If this rule is used (which is the default), the following method is used to determine whether a given point is “inside” the path: From the point, shoot a ray in some direction towards infinity (the direction is chosen such that no strange borderline cases occur). Then the ray may hit the path. Whenever it hits the path, we increase or decrease a counter, which is initially zero. If the ray hits the path as the path goes “from left to right” (relative to the ray), the counter is increased, otherwise it is decreased. Then, at the end, we check whether the counter is nonzero (hence the name). If so, the point is deemed to lie “inside,” otherwise it is “outside.” Sounds complicated? It is.

  \begin{tikzpicture}
  \filldraw[fill=examplefill]
  % Clockwise rectangle
  (0,0) -- (0,1) -- (1,1) -- (1,0) -- cycle
  % Counter-clockwise rectangle
  (0.25,0.25) -- (0.75,0.25) -- (0.75,0.75) -- (0.25,0.75) -- cycle;
  \draw[->] (0,1) (.4,1);
  \draw[->] (0.75,0.75) (0.3,.75);
  \draw[->] (0.5,0.5) -- +(0,1) node[above] {crossings: $-1+1 = 0$};
  \begin{scope}[yshift=-3cm]
  \filldraw[fill=examplefill]
  % Clockwise rectangle
  (0,0) -- (0,1) -- (1,1) -- (1,0) -- cycle
  % Clockwise rectangle
  (0.25,0.25) -- (0.25,0.75) -- (0.75,0.75) -- (0.75,0.25) -- cycle;
  \draw[->] (0,1) (.4,1);
  \draw[->] (0.25,0.75) (0.4,.75);
  \draw[->] (0.5,0.5) -- +(0,1) node[above] {crossings: $1+1 = 2$};
  \end{scope}
  \end{tikzpicture}

- even odd rule This option causes a different method to be used for determining the inside and outside of paths. While it is less flexible, it turns out to be more intuitive.

  With this method, we also shoot rays from the point for which we wish to determine whether it is inside or outside the filling area. However, this time we only count how often we “hit” the path and declare the point to be “inside” if the number of hits is odd.

  Using the even-odd rule, it is easy to “drill holes” into a path.

  \begin{tikzpicture} \filldraw[fill=examplefill,even odd rule] (0,0) rectangle (1,1) (0.5,0.5) circle (0.4cm); \draw[->] (0.5,0.5) -- +(0,1) [above] node{crossings: $1+1 = 2$}; \end{tikzpicture}

##### 10.3.2 Graphic Parameters: Fill Opacity

Analogously to the draw opacity, you can also set the filling opacity:

- fill opacity=<value> This option sets the opacity of fillings. In addition to filling operations, this opacity also applies to text and images.

  Note, again, that when you use PostScript as your output format, this option works only with recent versions of GhostScript.

  \begin{tikzpicture}[thick,fill opacity=0.5] \filldraw[fill=red] (0:1cm) circle (12mm); \filldraw[fill=green] (120:1cm) circle (12mm); \filldraw[fill=blue] (-120:1cm) circle (12mm); \end{tikzpicture}

  \begin{tikzpicture} \fill[red] (0,0) rectangle (3,2); \node at (0,0) {\huge A}; \node[fill opacity=0.5] at (3,2) {\huge B}; \end{tikzpicture}

#### 10.4 Shading a Path

You can shade a path using the shade option. A shading is like a filling, only the shading changes its color smoothly from one color to another.

- shade Causes the path to be shaded using the currently selected shading (more on this later). If this option is used together with the draw option, then the path is first shaded, then drawn.

  It is not an error to use this option together with the fill option, but it makes no sense.

  \tikz \shade (0,0) circle (1ex);

  \tikz \shadedraw (0,0) circle (1ex);

For some shadings it is not really clear how they can “fill” the path. For example, the ball shading normally looks like this:
. How is this supposed to shade a rectangle? Or a triangle?

To solve this problem, the predefined shadings like ball or axis fill a large rectangle completely in a sensible way. Then, when the shading is used to “shade” a path, what actually happens is that the path is temporarily used for clipping and then the rectangular shading is drawn, scaled and shifted such that all parts of the path are filled.

##### 10.4.1 Choosing a Shading Type

The default shading is a smooth transition from gray to white and from above to bottom. However, other shadings are also possible, for example a shading that will sweep a color from the center to the corners outward. To choose the shading, you can use the shading= option, which will also automatically invoke the shade option. Note that this does not change the shading color, only the way the colors sweep. For changing the colors, other options are needed, which are explained below.

- shading=<name> This selects a shading named <name>. The following shadings are predefined:
  - axis This is the default shading in which the color changes gradually between three horizontal lines. The top line is at the top (uppermost) point of the path, the middle is in the middle, the bottom line is at the bottom of the path.

    \tikz \shadedraw [shading=axis] (0,0) rectangle (1,1);

    The default top color is gray, the default bottom color is white, the default middle is the “middle” of these two.

  - radial This shading fills the path with a gradual sweep from a certain color in the middle to another color at the border. If the path is a circle, the outer color will be reached exactly at the border. If the shading is not a circle, the outer color will continue a bit towards the corners. The default inner color is gray, the default outer color is white.

    \tikz \shadedraw [shading=radial] (0,0) rectangle (1,1);

  - ball This shading fills the path with a shading that “looks like a ball.” The default “color” of the ball is blue (for no particular reason).

    \tikz \shadedraw [shading=ball] (0,0) rectangle (1,1);

    \tikz \shadedraw [shading=ball] (0,0) circle (.5cm);

- shading angle=<degrees> This option rotates the shading (not the path!) by the given angle. For example, we can turn a top-to-bottom axis shading into a left-to-right shading by rotating it by 90o.

  \tikz \shadedraw [shading=axis,shading angle=90] (0,0) rectangle (1,1);

You can also define new shading types yourself. However, for this, you need to use the basic layer directly, which is, well, more basic and harder to use. Details on how to create a shading appropriate for filling paths are given in Section 28.3.

##### 10.4.2 Choosing a Shading Color

The following options can be used to change the colors used for shadings. When one of these options is given, the shade option is automatically selected and also the “right” shading.

- top color=<color> This option prescribes the color to be used at the top in an axis shading. When this option is given, several things happen:
  1. The shade option is selected.
  2. The shading=axis option is selected.
  3. The middle color of the axis shading is set to the average of the given top color <color> and of whatever color is currently selected for the bottom.
  4. The rotation angle of the shading is set to 0.

  \tikz \draw[top color=red] (0,0) rectangle (2,1);

- bottom color=<color> This option works like top color, only for the bottom color.
- middle color=<color> This option specifies the color for the middle of an axis shading. It also sets the shade and shading=axis options, but it does not change the rotation angle.

  Note: Since both top color and bottom color change the middle color, this option should be given last if all of these options need to be given:

  \tikz \draw[top color=white,bottom color=black,middle color=red] (0,0) rectangle (2,1);

- left color=<color> This option does exactly the same as top color, except that the shading angle is set to 90o.
- right color=<color> Works like left color.
- inner color=<color> This option sets the color used at the center of a radial shading. When this option is used, the shade and shading=radial options are set.

  \tikz \draw[inner color=red] (0,0) rectangle (2,1);

- outer color=<color> This option sets the color used at the border and outside of a radial shading.

  \tikz \draw[outer color=red,inner color=white] (0,0) rectangle (2,1);

- ball color=<color> This option sets the color used for the ball shading. It sets the shade and shading=ball options. Note that the ball will never “completely” have the color <color>. At its “highlight” spot a certain amount of white is mixed in, at the border a certain amount of black. Because of this, it also makes sense to say ball color=white or ball color=black

  \begin{tikzpicture} \shade[ball color=white] (0,0) circle (2ex); \shade[ball color=red] (1,0) circle (2ex); \shade[ball color=black] (2,0) circle (2ex); \end{tikzpicture}

#### 10.5 Establishing a Bounding Box

PGF is reasonably good at keeping track of the size of your picture and reserving just the right amount of space for it in the main document. However, in some cases you may want to say things like “do not count this for the picture size” or “the picture is actually a little large.” For this you can use the option use as bounding box or the command \useasboundingbox, which is just a shorthand for \path[use as bounding box].

- use as bounding box Normally, when this option is given on a path, the bounding box of the present path is used to determine the size of the picture and the size of all subsequent paths are ignored. However, if there were previous path operations that have already established a larger bounding box, it will not be made smaller by this operation.

  In a sense, use as bounding box has the same effect as clipping all subsequent drawing against the current path--without actually doing the clipping, only making PGF treat everything as if it were clipped.

  The first application of this option is to have a {tikzpicture} overlap with the main text:

  Left of picture
  right of picture.

  Left of picture\begin{tikzpicture} \draw[use as bounding box] (2,0) rectangle (3,1); \draw (1,0) -- (4,.75); \end{tikzpicture}right of picture.

  In a second application this option can be used to get better control over the white space around the picture:

  Left of picture
  right of picture.

  Left of picture \begin{tikzpicture} \useasboundingbox (0,0) rectangle (3,1); \fill (.75,.25) circle (.5cm); \end{tikzpicture} right of picture.

  Note: If this option is used on a path inside a TEX group (scope), the effect “lasts” only till the end of the scope. Again, this behavior is the same as for clipping.

There is a node that allows you to get the size of the current bounding box. The current bounding box node has the rectangle shape rectangle shape and its size is always the size of the current bounding box.

\begin{tikzpicture} \draw[red] (0,0) circle (2pt); \draw[red] (2,1) circle (3pt); \draw (current bounding box.south west) rectangle (current bounding box.north east); \draw[red] (3,-1) circle (4pt); \draw[thick] (current bounding box.south west) rectangle (current bounding box.north east); \end{tikzpicture}

#### 10.6 Using a Path For Clipping

To use a path for clipping, use the clip option.

- clip This option causes all subsequent drawings to be clipped against the current path and the size of subsequent paths will not be important for the picture size. If you clip against a self-intersecting path, the even-odd rule or the nonzero winding number rule is used to determine whether a point is inside or outside the clipping region.

  The clipping path is a graphic state parameter, so it will be reset at the end of the current scope. Multiple clippings accumulate, that is, clipping is always done against the intersection of all clipping areas that have been specified inside the current scopes. The only way of enlarging the clipping area is to end a {scope}.

  \begin{tikzpicture} \draw[clip] (0,0) circle (1cm); \fill[red] (1,0) circle (1cm); \end{tikzpicture}

  It is usually a very good idea to apply the clip option only to the first path command in a scope.

  If you “only wish to clip” and do not wish to draw anything, you can use the \clip command, which is a shorthand for \path[clip].

  \begin{tikzpicture} \clip (0,0) circle (1cm); \fill[red] (1,0) circle (1cm); \end{tikzpicture}

  To keep clipping local, use {scope} environments as in the following example:

  \begin{tikzpicture} \draw (0,0) -- ( 0:1cm); \draw (0,0) -- (10:1cm); \draw (0,0) -- (20:1cm); \draw (0,0) -- (30:1cm); \begin{scope}[fill=red] \fill[clip] (0.2,0.2) rectangle (0.5,0.5); \draw (0,0) -- (40:1cm); \draw (0,0) -- (50:1cm); \draw (0,0) -- (60:1cm); \end{scope} \draw (0,0) -- (70:1cm); \draw (0,0) -- (80:1cm); \draw (0,0) -- (90:1cm); \end{tikzpicture}

  There is a slightly annoying catch: You cannot specify certain graphic options for the command used for clipping. For example, in the above code we could not have moved the fill=red to the \fill command. The reasons for this have to do with the internals of the PDF specification. You do not want to know the details. It is best simply not to specify any options for these commands.

[next] [prev] [prev-tail] [front] [up]