summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tutorial.tex
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tutorial.tex')
-rw-r--r--Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tutorial.tex306
1 files changed, 179 insertions, 127 deletions
diff --git a/Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tutorial.tex b/Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tutorial.tex
index b2dcfbe5a05..99585ce2b48 100644
--- a/Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tutorial.tex
+++ b/Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tutorial.tex
@@ -9,9 +9,9 @@
\section{Tutorial: A Picture for Karl's Students}
-This tutorial is intended for new users of \pgfname\ and \tikzname. It
-does not give an exhaustive account of all the features of \tikzname\ or
-\pgfname, just of those that you are likely to use right away.
+This tutorial is intended for new users of \tikzname. It
+does not give an exhaustive account of all the features of \tikzname,
+just of those that you are likely to use right away.
Karl is a math and chemistry high-school teacher. He used to create
the graphics in his worksheets and exams using \LaTeX's |{picture}|
@@ -66,7 +66,7 @@ cosine. What he would like to have is something that looks like this
% The graphic
\draw[help lines,step=0.5cm] (-1.4,-1.4) grid (1.4,1.4);
- \draw (0,0) circle (1cm);
+ \draw (0,0) circle [radius=1cm];
\begin{scope}[axes]
\draw[->] (-1.5,0) -- (1.5,0) node[right] {$x$};
@@ -236,9 +236,7 @@ His version of the example looks like this:
\end{codeexample}
Hans will now typeset this file in the usual way using
-|texexec|\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).}.
+|texexec| or |context|.
@@ -288,10 +286,10 @@ $z$ and the tangent of the curve at point $z$ will go through $w$.
Here is an example (the control points have been added for clarity):
\begin{codeexample}[]
\begin{tikzpicture}
- \filldraw [gray] (0,0) circle (2pt)
- (1,1) circle (2pt)
- (2,1) circle (2pt)
- (2,0) circle (2pt);
+ \filldraw [gray] (0,0) circle [radius=2pt]
+ (1,1) circle [radius=2pt]
+ (2,1) circle [radius=2pt]
+ (2,0) circle [radius=2pt];
\draw (0,0) .. controls (1,1) and (2,1) .. (2,0);
\end{tikzpicture}
\end{codeexample}
@@ -320,38 +318,36 @@ way to be extremely awkward. Fortunately, there is a much simpler way.
\subsection{Circle Path Construction}
In order to draw a circle, the path construction operation |circle| can
-be used. This operation is followed by a radius in round brackets as in
+be used. This operation is followed by a radius in brackets as in
the following example: (Note that the previous position is used as the
\emph{center} of the circle.)
\begin{codeexample}[]
-\tikz \draw (0,0) circle (10pt);
+\tikz \draw (0,0) circle [radius=10pt];
\end{codeexample}
You can also append an ellipse to the path using the |ellipse|
-operation. Instead of a single radius you can specify two of them, one
-for the $x$-direction and one for the $y$-direction, separated by
-|and|:
+operation. Instead of a single radius you can specify two of them:
\begin{codeexample}[]
-\tikz \draw (0,0) ellipse (20pt and 10pt);
+\tikz \draw (0,0) ellipse [x radius=20pt, y radius=10pt];
\end{codeexample}
To draw an ellipse whose axes are not horizontal and vertical, but
point in an arbitrary direction (a ``turned ellipse'' like \tikz
-\draw[rotate=30] (0,0) ellipse (6pt and 3pt);) you can use
+\draw[rotate=30] (0,0) ellipse [x radius=6pt, y radius=3pt];) you can use
transformations, which are explained later. The code for the little
-ellipse is |\tikz \draw[rotate=30] (0,0) ellipse (6pt and 3pt);|, by
+ellipse is |\tikz \draw[rotate=30] (0,0) ellipse [x radius=6pt, y radius=3pt];|, by
the way.
So, returning to Karl's problem, he can write
-|\draw (0,0) circle (1cm);| to draw the circle:
+|\draw (0,0) circle [radius=1cm];| to draw the circle:
\begin{codeexample}[]
\begin{tikzpicture}
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
- \draw (0,0) circle (1cm);
+ \draw (0,0) circle [radius=1cm];
\end{tikzpicture}
\end{codeexample}
@@ -380,7 +376,7 @@ rectangle. So, let us add two rectangles to the picture:
\begin{tikzpicture}
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
- \draw (0,0) circle (1cm);
+ \draw (0,0) circle [radius=1cm];
\draw (0,0) rectangle (0.5,0.5);
\draw (-0.5,-0.5) rectangle (-1,-1);
\end{tikzpicture}
@@ -415,7 +411,7 @@ For Karl, the following code could be used:
\begin{tikzpicture}
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
- \draw (0,0) circle (1cm);
+ \draw (0,0) circle [radius=1cm];
\draw[step=.5cm] (-1.4,-1.4) grid (1.4,1.4);
\end{tikzpicture}
\end{codeexample}
@@ -434,7 +430,7 @@ top.
\draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
- \draw (0,0) circle (1cm);
+ \draw (0,0) circle [radius=1cm];
\end{tikzpicture}
\end{codeexample}
@@ -508,18 +504,16 @@ very thick lines, |ultra thick| yields really, really thick lines and
|ultra thin| yields lines that are so thin that low-resolution printers
and displays will have trouble showing them. He wonders what gives
lines of ``normal'' thickness. It turns out that |thin| is the correct
-choice. This seems strange to Karl, but his son explains him that
-\LaTeX\ has two commands called |\thinlines| and |\thicklines| and
-that |\thinlines| gives the line width of ``normal'' lines, more
-precisely, of the thickness that, say, the stem of a letter like ``T''
-or ``i'' has. Nevertheless, Karl would like to know whether there is
+choice, since it gives the same thickness as \TeX's |\hrule|
+command. Nevertheless, Karl would like to know whether there is
anything ``in the middle'' between |thin| and |thick|. There is:
|semithick|.
Another useful thing one can do with lines is to dash or dot them. For
this, the two styles |dashed| and |dotted| can be used, yielding
-\tikz \draw[dashed] (0,0) -- (10pt,0pt); and \tikz \draw[dotted] (0,0)
--- (10pt,0pt);. Both options also exist in a loose and a dense
+\tikz[baseline] \draw[dashed] (0,.5ex) -- ++(2em,0pt); and
+\tikz[baseline] \draw[dotted] (0,.5ex)
+-- ++(2em,0pt);. Both options also exist in a loose and a dense
version, called |loosely dashed|, |densely dashed|, |loosely dotted|,
and |densely dotted|. If he really, really needs to, Karl can also
define much more complex dashing patterns with the |dash pattern|
@@ -533,26 +527,23 @@ patterns are evil. Karl's students do not care about dashing patterns.
Our next obstacle is to draw the arc for the angle. For this, the
|arc| path construction operation is useful, which draws part of a
-circle or ellipse. This |arc| operation must be followed by a triple in
-rounded brackets, where the components of the triple are separated by
-colons. The first two components are angles, the last one is a
-radius. An example would be |(10:80:10pt)|, which means ``an arc from
-10 degrees to 80 degrees on a circle of radius 10pt.'' Karl obviously
+circle or ellipse. This |arc| operation is followed by options in
+brackets that specify the arc. An example would be \texttt{arc[start
+ angle=10, end angle=80, radius=10pt]}, which means exactly what it
+says. Karl obviously
needs an arc from $0^\circ$ to $30^\circ$. The radius should be
something relatively small, perhaps around one third of the circle's
-radius. This gives: |(0:30:3mm)|.
-
-When one uses the arc path construction operation, the specified arc will
-be added with its starting point at the current position. So, we first
-have to ``get there.''
+radius. When one uses the arc path construction operation, the
+specified arc will be added with its starting point at the current
+position. So, we first have to ``get there.''
\begin{codeexample}[]
\begin{tikzpicture}
\draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
- \draw (0,0) circle (1cm);
- \draw (3mm,0mm) arc (0:30:3mm);
+ \draw (0,0) circle [radius=1cm];
+ \draw (3mm,0mm) arc [start angle=0, end angle=30, radius=3mm];
\end{tikzpicture}
\end{codeexample}
@@ -567,8 +558,8 @@ causes this option to apply to everything within.
\draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
- \draw (0,0) circle (1cm);
- \draw (3mm,0mm) arc (0:30:3mm);
+ \draw (0,0) circle [radius=1cm];
+ \draw (3mm,0mm) arc [start angle=0, end angle=30, radius=3mm];
\end{tikzpicture}
\end{codeexample}
@@ -576,7 +567,9 @@ As for circles, you can specify ``two'' radii in order to get an
elliptical arc.
\begin{codeexample}[]
- \tikz \draw (0,0) arc (0:315:1.75cm and 1cm);
+ \tikz \draw (0,0)
+ arc [start angle=0, end angle=315,
+ x radius=1.75cm, y radius=1cm];
\end{codeexample}
@@ -585,7 +578,7 @@ elliptical arc.
In order to save space in this manual, it would be nice to clip Karl's
graphics a bit so that we can focus on the ``interesting''
parts. Clipping is pretty easy in \tikzname. You can use the |\clip|
-command clip all subsequent drawing. It works like |\draw|, only it
+command to clip all subsequent drawing. It works like |\draw|, only it
does not draw anything, but uses the given path to clip everything
subsequently.
@@ -595,8 +588,8 @@ subsequently.
\draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
- \draw (0,0) circle (1cm);
- \draw (3mm,0mm) arc (0:30:3mm);
+ \draw (0,0) circle [radius=1cm];
+ \draw (3mm,0mm) arc [start angle=0, end angle=30, radius=3mm];
\end{tikzpicture}
\end{codeexample}
@@ -614,8 +607,8 @@ and |\clip| is a shorthand for |\path[clip]| and you could also say
\draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
- \draw (0,0) circle (1cm);
- \draw (3mm,0mm) arc (0:30:3mm);
+ \draw (0,0) circle [radius=1cm];
+ \draw (3mm,0mm) arc [start angle=0, end angle=30, radius=3mm];
\end{tikzpicture}
\end{codeexample}
@@ -666,13 +659,14 @@ with a very light green. For this he uses |\fill| instead of
\draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
- \draw (0,0) circle (1cm);
- \fill[green!20!white] (0,0) -- (3mm,0mm) arc (0:30:3mm) -- (0,0);
+ \draw (0,0) circle [radius=1cm];
+ \fill[green!20!white] (0,0) -- (3mm,0mm)
+ arc [start angle=0, end angle=30, radius=3mm] -- (0,0);
\end{tikzpicture}
\end{codeexample}
The color |green!20!white| means 20\% green and 80\% white mixed
-together. Such color expression are possible since \pgfname\ uses Uwe
+together. Such color expression are possible since \tikzname\ uses Uwe
Kern's |xcolor| package, see the documentation of that package for
details on color expressions.
@@ -681,7 +675,8 @@ What would have happened, if Karl had not ``closed'' the path using
so this could have been omitted. Indeed, it would even have been
better to write the following, instead:
\begin{codeexample}[code only]
- \fill[green!20!white] (0,0) -- (3mm,0mm) arc (0:30:3mm) -- cycle;
+ \fill[green!20!white] (0,0) -- (3mm,0mm)
+ arc [start angle=0, end angle=30, radius=3mm] -- cycle;
\end{codeexample}
The |--cycle| causes the current path to be closed (actually the
current part of the current path) by smoothly joining the first and
@@ -708,9 +703,9 @@ arguments like this:
\draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
- \draw (0,0) circle (1cm);
- \filldraw[fill=green!20!white, draw=green!50!black]
- (0,0) -- (3mm,0mm) arc (0:30:3mm) -- cycle;
+ \draw (0,0) circle [radius=1cm];
+ \filldraw[fill=green!20!white, draw=green!50!black] (0,0) -- (3mm,0mm)
+ arc [start angle=0, end angle=30, radius=3mm] -- cycle;
\end{tikzpicture}
\end{codeexample}
@@ -719,7 +714,7 @@ arguments like this:
\subsection{Shading}
Karl briefly considers the possibility of making the angle ``more
-fancy'' by \emph{shading} it. Instead of filling the with a uniform
+fancy'' by \emph{shading} it. Instead of filling the area with a uniform
color, a smooth transition between different colors is used. For this,
|\shade| and |\shadedraw|, for shading and drawing at the same time,
can be used:
@@ -747,9 +742,10 @@ For Karl, the following might be appropriate:
\draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
- \draw (0,0) circle (1cm);
+ \draw (0,0) circle [radius=1cm];
\shadedraw[left color=gray,right color=green, draw=green!50!black]
- (0,0) -- (3mm,0mm) arc (0:30:3mm) -- cycle;
+ (0,0) -- (3mm,0mm)
+ arc [start angle=0, end angle=30, radius=3mm] -- cycle;
\end{tikzpicture}
\end{codeexample}
@@ -760,7 +756,7 @@ adding anything to the picture.
\subsection{Specifying Coordinates}
Karl now wants to add the sine and cosine lines. He knows already that
-he can use the |color=| option to set the lines's colors. So, what is
+he can use the |color=| option to set the lines' colors. So, what is
the best way to specify the coordinates?
There are different ways of specifying coordinates. The easiest way is
@@ -788,9 +784,9 @@ For example, we can draw the sine line as follows:
\draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
- \draw (0,0) circle (1cm);
- \filldraw[fill=green!20,draw=green!50!black]
- (0,0) -- (3mm,0mm) arc (0:30:3mm) -- cycle;
+ \draw (0,0) circle [radius=1cm];
+ \filldraw[fill=green!20,draw=green!50!black] (0,0) -- (3mm,0mm)
+ arc [start angle=0, end angle=30, radius=3mm] -- cycle;
\draw[red,very thick] (30:1cm) -- +(0,-0.5);
\end{tikzpicture}
\end{codeexample}
@@ -813,15 +809,15 @@ Next, let us draw the cosine line. One way would be to say
\draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
- \draw (0,0) circle (1cm);
- \filldraw[fill=green!20,draw=green!50!black] (0,0) -- (3mm,0mm) arc
- (0:30:3mm) -- cycle;
+ \draw (0,0) circle [radius=1cm];
+ \filldraw[fill=green!20,draw=green!50!black] (0,0) -- (3mm,0mm)
+ arc [start angle=0, end angle=30, radius=3mm] -- cycle;
\draw[red,very thick] (30:1cm) -- +(0,-0.5);
\draw[blue,very thick] (30:1cm) ++(0,-0.5) -- (0,0);
\end{tikzpicture}
\end{codeexample}
-Note the there is no |--| between |(30:1cm)| and |++(0,-0.5)|. In
+Note that there is no |--| between |(30:1cm)| and |++(0,-0.5)|. In
detail, this path is interpreted as follows: ``First, the |(30:1cm)|
tells me to move by pen to $(\cos 30^\circ,1/2)$. Next, there comes
another coordinate specification, so I move my pen there without drawing
@@ -861,9 +857,18 @@ economically like this (either with a single of a double |+|):
\subsection{Intersecting Paths}
Karl is left with the line for $\tan \alpha$, which seems difficult to
-specify using transformations and polar coordinates. For this he needs
-another way of specifying coordinates: Karl can specify intersections
-of paths as coordinates. The line for $\tan \alpha$ starts at $(1,0)$
+specify using transformations and polar coordinates. The first -- and
+easiest -- thing he can do is so simply use the coordinate
+|(1,{tan(30)})| since \tikzname's math engine knows how to compute
+things like |tan(30)|. Note the added braces since, otherwise,
+\tikzname's parser would think that the first closing parenthesis ends
+the coordinate (in general, you need to add braces around components
+of coordinates when these components contain parentheses).
+
+Karl can, however, also use a more elaborate, but also more
+``geometric'' way of computing the length of the orange line: He can
+specify intersections of paths as coordinates. The line for $\tan
+\alpha$ starts at $(1,0)$
and goes upward to a point that is at the intersection of a line going
``up'' and a line going from the origin through |(30:1cm)|. Such
computations are made available by the |intersections| library.
@@ -889,7 +894,7 @@ later reference.
Karl now wants to add the little arrow tips at the end of the axes. He has
noticed that in many plots, even in scientific journals, these arrow tips
-seem to missing, presumably because the generating programs cannot
+seem to be missing, presumably because the generating programs cannot
produce them. Karl thinks arrow tips belong at the end of axes. His
son agrees. His students do not care about arrow tips.
@@ -902,9 +907,9 @@ It turns out that adding arrow tips is pretty easy: Karl adds the option
\draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
\draw[->] (-1.5,0) -- (1.5,0);
\draw[->] (0,-1.5) -- (0,1.5);
- \draw (0,0) circle (1cm);
- \filldraw[fill=green!20,draw=green!50!black] (0,0) -- (3mm,0mm) arc
- (0:30:3mm) -- cycle;
+ \draw (0,0) circle [radius=1cm];
+ \filldraw[fill=green!20,draw=green!50!black] (0,0) -- (3mm,0mm)
+ arc [start angle=0, end angle=30, radius=3mm] -- cycle;
\draw[red,very thick] (30:1cm) -- +(0,-0.5);
\draw[blue,very thick] (30:1cm) ++(0,-0.5) -- (0,0);
@@ -921,38 +926,35 @@ arrow tips at both ends of the path.
There are certain restrictions to the kind of paths to which arrow tips
can be added. As a rule of thumb, you can add arrow tips only to a
-single open ``line.'' For example, you should not try to add tips to,
-say, a rectangle or a circle. (You can try, but no guarantees as to what
-will happen now or in future versions.) However, you can add arrow
+single open ``line.'' For example, you cannot add tips to,
+say, a rectangle or a circle. However, you can add arrow
tips to curved paths and to paths that have several segments, as in
the following examples:
\begin{codeexample}[]
\begin{tikzpicture}
- \draw [<->] (0,0) arc (180:30:10pt);
+ \draw [<->] (0,0) arc [start angle=180, end angle=30, radius=10pt];
\draw [<->] (1,0) -- (1.5cm,10pt) -- (2cm,0pt) -- (2.5cm,10pt);
\end{tikzpicture}
\end{codeexample}
Karl has a more detailed look at the arrow that \tikzname\ puts at the
-end. It looks like this when he zooms it: \tikz { \useasboundingbox
- (0pt,-.5ex) rectangle (10pt,.5ex); \draw[->,line width=1pt] (0pt,0pt) --
- (10pt,0pt); }. The shape seems vaguely familiar and, indeed, this is
-exactly the end of \TeX's standard arrow used in something like
-$f\colon A \to B$.
-
+end. It looks like this when he zooms it: \tikz[baseline]
+\draw[->,line width=1pt] (0pt,.5ex) -- ++(10pt,0pt);. The shape seems
+vaguely familiar and, indeed, this is exactly the end of \TeX's
+standard arrow used in something like $f\colon A \to B$.
Karl likes the arrow, especially since it is not ``as thick'' as the
arrows offered by many other packages. However, he expects that,
sometimes, he might need to use some other kinds of arrow.
-To do so, Karl can say |>=|\meta{right arrow tip kind}, where
-\meta{right arrow tip kind} is a special arrow tip specification. For
-example, if Karl says |>=stealth|, then he tells \tikzname\
+To do so, Karl can say |>=|\meta{kind of end arrow tip}, where
+\meta{kind of end arrow tip} is a special arrow tip specification. For
+example, if Karl says |>=Stealth|, then he tells \tikzname\
that he would like ``stealth-fighter-like'' arrow tips:
\begin{codeexample}[]
-\begin{tikzpicture}[>=stealth]
- \draw [->] (0,0) arc (180:30:10pt);
+\begin{tikzpicture}[>=Stealth]
+ \draw [->] (0,0) arc [start angle=180, end angle=30, radius=10pt];
\draw [<<-,very thick] (1,0) -- (1.5cm,10pt) -- (2cm,0pt) -- (2.5cm,10pt);
\end{tikzpicture}
\end{codeexample}%>>
@@ -962,12 +964,9 @@ necessary. He is not really mollified when his son tells him that
Microsoft's PowerPoint uses the same name. He decides to have his
students discuss this at some point.
-In addition to |stealth| there are several other predefined arrow tip
-kinds Karl can choose from, see
-Section~\ref{section-library-arrows}. Furthermore, he can define
-arrows types himself, if he needs new ones.
-
-
+In addition to |Stealth| there are several other predefined kinds of
+arrow tips Karl can choose from, see Section~\ref{section-arrows}. Furthermore,
+he can define arrows types himself, if he needs new ones.
\subsection{Scoping}
@@ -1016,7 +1015,7 @@ can be given anywhere on the path. So, instead of
|\draw (0,0) [thin] -- (1,0);| or |\draw (0,0) -- (1,0) [thin];|; all
of these have the same effect. This might seem strange since in the
last case, it would appear that the |thin| should take effect only
-``after'' the line from $(0,0)$ to $(1,0)$ has been draw. However,
+``after'' the line from $(0,0)$ to $(1,0)$ has been drawn. However,
most graphic options only apply to the whole path. Indeed, if you say
both |thin| and |thick| on the same path, the last option given will
``win.''
@@ -1035,11 +1034,11 @@ apply only to this path.
When you specify a coordinate like |(1cm,1cm)|, where is that
coordinate placed on the page? To determine the position, \tikzname,
\TeX, and \textsc{pdf} or PostScript all apply certain transformations
-to the given coordinate in order to determine the finally position on
+to the given coordinate in order to determine the final position on
the page.
\tikzname\ provides numerous options that allow you to transform
-coordinates in \pgfname's private coordinate system. For example, the
+coordinates in \tikzname's private coordinate system. For example, the
|xshift| option allows you to shift all subsequent points by a certain
amount:
@@ -1049,15 +1048,15 @@ amount:
It is important to note that you can change transformation ``in the
middle of a path,'' a feature that is not supported by \pdf\
-or PostScript. The reason is that \pgfname\ keeps track of its own
+or PostScript. The reason is that \tikzname\ keeps track of its own
transformation matrix.
Here is a more complicated example:
\begin{codeexample}[]
\begin{tikzpicture}[even odd rule,rounded corners=2pt,x=10pt,y=10pt]
- \filldraw[fill=examplefill] (0,0) rectangle (1,1)
- [xshift=5pt,yshift=5pt] (0,0) rectangle (1,1)
- [rotate=30] (-1,-1) rectangle (2,2);
+ \filldraw[fill=yellow!80!black] (0,0) rectangle (1,1)
+ [xshift=5pt,yshift=5pt] (0,0) rectangle (1,1)
+ [rotate=30] (-1,-1) rectangle (2,2);
\end{tikzpicture}
\end{codeexample}
@@ -1084,11 +1083,11 @@ $-1/2$, $1/2$, and $1$. For this, it would be nice to use some kind of
these positions. There are different packages for doing this. \LaTeX\
has its own internal command for this, |pstricks| comes along with the
powerful |\multido| command. All of these can be used together with
-\pgfname\ and \tikzname, so if you are familiar with them, feel free to
-use them. \pgfname\ introduces yet another command, called |\foreach|,
+\tikzname, so if you are familiar with them, feel free to
+use them. \tikzname\ introduces yet another command, called |\foreach|,
which I introduced since I could never remember the syntax of the other
packages. |\foreach| is defined in the package |pgffor| and can be used
-independently of \pgfname. \tikzname\ includes it automatically.
+independently \tikzname, but \tikzname\ includes it automatically.
In its basic form, the |\foreach| command is easy to use:
\begin{codeexample}[]
@@ -1107,11 +1106,11 @@ For Karl and the ticks on the axes, he could use the following code:
\begin{tikzpicture}[scale=3]
\clip (-0.1,-0.2) rectangle (1.1,1.51);
\draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
- \filldraw[fill=green!20,draw=green!50!black] (0,0) -- (3mm,0mm) arc
- (0:30:3mm) -- cycle;
+ \filldraw[fill=green!20,draw=green!50!black] (0,0) -- (3mm,0mm)
+ arc [start angle=0, end angle=30, radius=3mm] -- cycle;
\draw[->] (-1.5,0) -- (1.5,0);
\draw[->] (0,-1.5) -- (0,1.5);
- \draw (0,0) circle (1cm);
+ \draw (0,0) circle [radius=1cm];
\foreach \x in {-1cm,-0.5cm,1cm}
\draw (\x,-1pt) -- (\x,1pt);
@@ -1189,7 +1188,7 @@ path has been completely drawn/filled/shaded/clipped/whatever.
\begin{codeexample}[]
\begin{tikzpicture}
\draw (0,0) rectangle (2,2);
- \draw (0.5,0.5) node [fill=examplefill]
+ \draw (0.5,0.5) node [fill=yellow!80!black]
{Text at \verb!node 1!}
-- (1.5,1.5) node {Text at \verb!node 2!};
\end{tikzpicture}
@@ -1201,7 +1200,7 @@ right of these positions. For this, every node object that you
put in your picture is equipped with several \emph{anchors}. For
example, the |north| anchor is in the middle at the upper end of the shape,
the |south| anchor is at the bottom and the |north east| anchor is in
-the upper right corner. When you given the option |anchor=north|, the
+the upper right corner. When you give the option |anchor=north|, the
text will be placed such that this northern anchor will lie on the
current position and the text is, thus, below the current
position. Karl uses this to draw the ticks as follows:
@@ -1210,10 +1209,10 @@ position. Karl uses this to draw the ticks as follows:
\begin{tikzpicture}[scale=3]
\clip (-0.6,-0.2) rectangle (0.6,1.51);
\draw[step=.5cm,help lines] (-1.4,-1.4) grid (1.4,1.4);
- \filldraw[fill=green!20,draw=green!50!black]
- (0,0) -- (3mm,0mm) arc (0:30:3mm) -- cycle;
+ \filldraw[fill=green!20,draw=green!50!black] (0,0) -- (3mm,0mm)
+ arc [start angle=0, end angle=30, radius=3mm] -- cycle;
\draw[->] (-1.5,0) -- (1.5,0); \draw[->] (0,-1.5) -- (0,1.5);
- \draw (0,0) circle (1cm);
+ \draw (0,0) circle [radius=1cm];
\foreach \x in {-1,-0.5,1}
\draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north] {$\x$};
@@ -1258,10 +1257,10 @@ will be used again. So, here is the new code for the ticks:
\begin{tikzpicture}[scale=3]
\clip (-0.6,-0.2) rectangle (0.6,1.51);
\draw[step=.5cm,help lines] (-1.4,-1.4) grid (1.4,1.4);
- \filldraw[fill=green!20,draw=green!50!black]
- (0,0) -- (3mm,0mm) arc (0:30:3mm) -- cycle;
+ \filldraw[fill=green!20,draw=green!50!black] (0,0) -- (3mm,0mm)
+ arc [start angle=0, end angle=30, radius=3mm] -- cycle;
\draw[->] (-1.5,0) -- (1.5,0); \draw[->] (0,-1.5) -- (0,1.5);
- \draw (0,0) circle (1cm);
+ \draw (0,0) circle [radius=1cm];
\foreach \x/\xtext in {-1, -0.5/-\frac{1}{2}, 1}
\draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north] {$\xtext$};
@@ -1280,7 +1279,7 @@ with a white color.
The next thing Karl wants to do is to add the labels like $\sin
\alpha$. For this, he would like to place a label ``in the middle of
-line.'' To do so, instead of specifying the label
+the line.'' To do so, instead of specifying the label
|node {$\sin\alpha$}| directly after one of the endpoints of the line
(which would place
the label at that endpoint), Karl can give the label directly after
@@ -1294,11 +1293,11 @@ modify this position:
\begin{tikzpicture}[scale=3]
\clip (-2,-0.2) rectangle (2,0.8);
\draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
- \filldraw[fill=green!20,draw=green!50!black] (0,0) -- (3mm,0mm) arc
- (0:30:3mm) -- cycle;
+ \filldraw[fill=green!20,draw=green!50!black] (0,0) -- (3mm,0mm)
+ arc [start angle=0, end angle=30, radius=3mm] -- cycle;
\draw[->] (-1.5,0) -- (1.5,0) coordinate (x axis);
\draw[->] (0,-1.5) -- (0,1.5) coordinate (y axis);
- \draw (0,0) circle (1cm);
+ \draw (0,0) circle [radius=1cm];
\draw[very thick,red]
(30:1cm) -- node[left=1pt,fill=white] {$\sin \alpha$} (30:1cm |- x axis);
@@ -1347,9 +1346,6 @@ desired effect. So, here is the full code:
important line/.style={very thick},
information text/.style={rounded corners,fill=red!10,inner sep=1ex}]
- % Local definitions
- \def\costhirty{0.8660256}
-
% Colors
\colorlet{anglecolor}{green!50!black}
\colorlet{sincolor}{red}
@@ -1359,7 +1355,7 @@ desired effect. So, here is the full code:
% The graphic
\draw[help lines,step=0.5cm] (-1.4,-1.4) grid (1.4,1.4);
- \draw (0,0) circle (1cm);
+ \draw (0,0) circle [radius=1cm];
\begin{scope}[axes]
\draw[->] (-1.5,0) -- (1.5,0) node[right] {$x$} coordinate(x axis);
@@ -1372,7 +1368,8 @@ desired effect. So, here is the full code:
\draw[yshift=\y cm] (1pt,0pt) -- (-1pt,0pt) node[left,fill=white] {$\ytext$};
\end{scope}
- \filldraw[fill=green!20,draw=anglecolor] (0,0) -- (3mm,0pt) arc(0:30:3mm);
+ \filldraw[fill=green!20,draw=anglecolor] (0,0) -- (3mm,0pt)
+ arc [start angle=0, end angle=30, radius=3mm];
\draw (15:2mm) node[anglecolor] {$\alpha$};
\draw[important line,sincolor]
@@ -1403,3 +1400,58 @@ desired effect. So, here is the full code:
};
\end{tikzpicture}
\end{codeexample}
+
+
+
+\subsection{Pics: The Angle Revisited}
+
+Karl expects that the code of certain parts of the picture he created
+might be so useful that he might wish to reuse them in the
+future. A natural thing to do is to create \TeX\ macros that store
+the code he wishes to reuse. However, \tikzname\ offers another way
+that is integrated directly into its parser: pics!
+
+A ``pic'' is ``not quite a full picture,'' hence the short name. The
+idea is that a pic is simply some code that you can add to a picture
+at different places using the |pic| command whose syntax is almost
+identical to the |node| command. The main difference is that instead
+of specifying some text in curly braces that should be shown, you
+specify the name of a predefined picture that should be shown.
+
+Defining new pics is easy enough, see Section~\ref{section-pics}, but
+right now we just want to use one such predefined pic: the |angle|
+pic. As the name suggests, it is a small drawing of an angle
+consisting of a little wedge and an arc together with some text (Karl
+needs to load the |angle| library and the |quotes| for the following
+examples). What makes this pic useful is the fact that the size of the
+wedge will be computed automatically.
+
+The |angle| pic draws an angle between the two lines $BA$ and $BC$,
+where $A$, $B$, and $C$ are three coordinates. In our case, $B$ is the
+origin, $A$ is somewhere on the $x$-axis and $C$ is somewhere on a
+line at $30^\circ$.
+
+\begin{codeexample}[]
+\begin{tikzpicture}[scale=3]
+ \coordinate (A) at (1,0);
+ \coordinate (B) at (0,0);
+ \coordinate (C) at (30:1cm);
+
+ \draw (A) -- (B) -- (C)
+ pic [draw=green!50!black, fill=green!20, angle radius=9mm,
+ "$\alpha$"] {angle = A--B--C};
+\end{tikzpicture}
+\end{codeexample}
+
+Let us see, what is happening here. First we have specified three
+\emph{coordinates} using the |\coordinate| command. It allows us to
+name a specific coordinate in the picture. Then comes something that
+starts as a normal |\draw|, but then comes the |pic| command. This
+command gets lots of options and, in curly braces, comes the most
+important point: We specify that we want to add an |angle| pic and
+this angle should be between the points we named |A|, |B|, and |C| (we
+could use other names). Note that the text that we want to be shown in
+the pic is specified in quotes inside the options of the |pic|, not
+inside the curly braces.
+
+To learn more about pics, please see Section~\ref{section-pics}. \ No newline at end of file