Creating vector graphics with LaTeX and TikZ
|
Areas
Note that you can fill areas with the \fill[<options>] <path>; command. You describe the path with the aforementioned commands. If you don't close the path, LaTeX does it for you automatically. The fill color is one of the options, with black as the default. Listing 9 shows an example in line 1: The area of a triangle appears in blue. You can omit the – cycle command, as you can see in line 2.
Listing 9
Areas
01 \tikz{\fill[blue] (0,0) |- (2,2) -- cycle;} 02 \tikz{\fill[blue] (0,0) |- (2,2);} 03 \tikz{\filldraw[fill=lightgray,draw=darkgray,line width=1pt] (0,0) |- (2,2) -- cycle;} 04 \tikz{\filldraw[fill=lightgray,draw=darkgray,line width=1pt] (0,0) |- (2,2);}
You can combine both commands for lines and areas. You then get a figure where the edges and areas are distinct. Listing 9 shows an example in line 3 in which the area of the triangle is filled with a light gray, whereas the outer lines are dark gray. If you omit the – cycle command, as in line 4, LaTeX closes the area automatically, but not the outer lines.
Shading
With shading, you apply a gradient to areas. You do this by replacing \fill with \shade (line 1) or \filldraw with \shadedraw (line 2 in Listing 10). By default, LaTeX handles shades by transitioning from gray to white from top to bottom. You can also alter the color and shading direction. Line 3 shows a shading transitioning from top to bottom from blue to gray, line 4 from left to right from red to gray, and line 5 from inside to outside from yellow to gray.
Listing 10
Shading
01 \tikz{\shade (0,0) circle (2);} 02 \tikz{\shadedraw (0,0) circle (2);} 03 \tikz{\shade[top color=blue, bottom color=gray] (0,0) circle (2);} 04 \tikz{\shade[left color=red, right color=gray] (0,0) circle (2);} 05 \tikz{\shade[inner color=yellow, outer color=gray] (0,0) circle (2);}
Buy this article as PDF
Pages: 6
(incl. VAT)