-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTikZ_basic.tex
741 lines (648 loc) · 26.1 KB
/
TikZ_basic.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
\documentclass[a4paper,12pt]{article}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{tikz}
%\title{Ti$k$Z reference}
%\author{Yi-Chen Zhang}
%\date{\today}
\begin{document}
\begin{center}
\textbf{\Large Ti$k$Z reference}\\
\bigskip
Yi-Chen Zhang\\
\smallskip
\today
\end{center}
The Ti$k$Z commands can be inside the environment \textbackslash begin\{tikzpicture\} \ldots \textbackslash end\{tikzpicture\} or simply use \textbackslash tikz clause. We run \textsf{pdflatex} or \textsf{latex} followed by \textsf{dvips} to execute the Ti$k$Z commends.
\section{Straight Path Construction}
%Let's get started with drawing a path. A path is a series of straight lines and curves that are connected. We start a path by specifying the coordinates of the start position as a point in brackets, as in $(0,0)$. The starting point is followed by a series of path extension operators `\textsf{-}\textsf{-}'. Then it must be followed by another coordinate and extends the path in a straight line to a new position. We can put some options in square brackets to describe the properties of the lines. This will be discussed later.
\begin{verbatim}
Useage:
\draw[options] (x1,y1) -- (x2,y2) -- (x3,y3);
Example:
\begin{tikzpicture}
\draw (-1.5,0) -- (1.5,0) -- (0,-1.5) -- (0,1.5);
\draw[thick, rounded corners=10pt] (0,0) -- (0,2) -- (1,3.25) --
(2,2) -- (2,0) -- (0,2) -- (2,2) -- (0,0) -- (2,0);
\end{tikzpicture}
\end{verbatim}
\tikz \draw (-1.5,0) -- (1.5,0) -- (0,-1.5) -- (0,1.5);
\begin{tikzpicture}
\draw[thick, rounded corners=10pt] (0,0) -- (0,2) -- (1,3.25) -- (2,2) -- (2,0) -- (0,2) -- (2,2) -- (0,0) -- (2,0); % -- cycle;
\end{tikzpicture}
\section{Circle Path Construction}
\begin{verbatim}
Usage:
\draw[options] (x,y) circle (raidus);
\draw[options] (x,y) ellipse (x.raidus anda y.radius);
Example:
\begin{tikzpicture}
\draw (0,0) circle (2pt);
\draw[red] (1,0) circle (3pt);
\draw[fill=red] (2,0) circle (4pt);
\draw[red,fill=red] (3,0) ellipse (10pt and 5pt);
\filldraw[blue,rotate=30] (3.5,-2) ellipse (10pt and 5pt); % another way
\end{tikzpicture}
\end{verbatim}
\begin{tikzpicture}
\draw (0,0) circle (2pt);
\draw[red] (1,0) circle (3pt);
\draw[fill=red] (2,0) circle (4pt);
\draw[red,fill=red] (3,0) ellipse (10pt and 5pt);
\filldraw[blue,rotate=30] (3.5,-2) ellipse (10pt and 5pt);
\end{tikzpicture}
\section{Curved Path Construction}
\begin{verbatim}
Usage:
\draw[options] (x1,y1) .. controls (x2,y2) and (x3,y3) .. (x4,y4);
Example:
\begin{tikzpicture}
\filldraw[gray] (0,0) circle (2pt) (1,1) circle (2pt)
(2,1) circle (2pt) (2,0) circle (2pt);
\draw (0,0) .. controls (1,1) and (2,1) .. (2,0);
\end{tikzpicture}
\end{verbatim}
\begin{tikzpicture}
\filldraw[gray] (0,0) circle (2pt) (1,1) circle (2pt)
(2,1) circle (2pt) (2,0) circle (2pt);
\draw (0,0) .. controls (1,1) and (2,1) .. (2,0);
\end{tikzpicture}
\section{Rectangle Path Construction}
\begin{verbatim}
Usage:
\draw[options] (x1,y1) rectangle (x2,y2);
\draw[options] (x,y) rectangle +(width,height);
Example:
\begin{tikzpicture}
\draw (-1,0) -- (1,0);
\draw (0,-1) -- (0,1);
\draw[rotate=30, fill=red] (-0.5,-0.5) rectangle (-1,-1);
\draw (2,-0.5) rectangle +(1,1);
\end{tikzpicture}
\end{verbatim}
\begin{tikzpicture}
\draw (-1,0) -- (1,0);
\draw (0,-1) -- (0,1);
\draw[rotate=30, fill=red] (-0.5,-0.5) rectangle (0.5,0.5);
\draw (2,-0.5) rectangle +(1,1);
\end{tikzpicture}
\section{Grid Path Construction}
\begin{verbatim}
Usage:
\draw[options] (x1,y1) grid (x2,y2);
\end{verbatim}
\begin{verbatim}
Example:
\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[step=2pt] (0,0) grid (10pt,10pt);
\end{tikzpicture}
\end{verbatim}
\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[step=2pt] (0,0) grid (10pt,10pt);
\end{tikzpicture}
\section{Drawing Options}
There are some drawing options that one can use to control the color, thickness, and line type.
\begin{itemize}
\item color:
blue \tikz \filldraw[blue] (0,0) rectangle (1.5em,1.5ex);,
black \tikz \filldraw[black] (0,0) rectangle (1.5em,1.5ex);,
brown \tikz \filldraw[brown] (0,0) rectangle (1.5em,1.5ex);,
cyan \tikz \filldraw[cyan] (0,0) rectangle (1.5em,1.5ex);,
gray \tikz \filldraw[gray] (0,0) rectangle (1.5em,1.5ex);,
green \tikz \filldraw[green] (0,0) rectangle (1.5em,1.5ex);,
lightgray \tikz \filldraw[lightgray] (0,0) rectangle (1.5em,1.5ex);,
lime \tikz \filldraw[lime] (0,0) rectangle (1.5em,1.5ex);,
magenta \tikz \filldraw[magenta] (0,0) rectangle (1.5em,1.5ex);,
orange \tikz \filldraw[orange] (0,0) rectangle (1.5em,1.5ex);,
pink \tikz \filldraw[pink] (0,0) rectangle (1.5em,1.5ex);,
purple \tikz \filldraw[purple] (0,0) rectangle (1.5em,1.5ex);,
red \tikz \filldraw[red] (0,0) rectangle (1.5em,1.5ex);,
yellow \tikz \filldraw[yellow] (0,0) rectangle (1.5em,1.5ex);,
teal \tikz \filldraw[teal] (0,0) rectangle (1.5em,1.5ex);,
violet \tikz \filldraw[violet] (0,0) rectangle (1.5em,1.5ex);,
white \tikz \draw[fill=white] (0,0) rectangle (1.5em,1.5ex);.\\
Note: Colors can also be mixed. The color \verb|[blue!40!white]| means $40\%$ blue and $60\%$ white mixed together.
\item thickness:
ultra thin \begin{tikzpicture} \filldraw[white] (0,0) rectangle (1em,1.5ex); \draw[ultra thin] (0,0.7ex) -- (1em,0.7ex);\end{tikzpicture},
very thin \begin{tikzpicture} \filldraw[white] (0,0) rectangle (1em,1.5ex); \draw[very thin] (0,0.7ex) -- (1em,0.7ex);\end{tikzpicture},
thin \begin{tikzpicture} \filldraw[white] (0,0) rectangle (1em,1.5ex); \draw[thin] (0,0.7ex) -- (1em,0.7ex);\end{tikzpicture},
semithick \begin{tikzpicture} \filldraw[white] (0,0) rectangle (1em,1.5ex); \draw[semithick] (0,0.7ex) -- (1em,0.7ex);\end{tikzpicture},
thick \begin{tikzpicture} \filldraw[white] (0,0) rectangle (1em,1.5ex); \draw[thick] (0,0.7ex) -- (1em,0.7ex);\end{tikzpicture},
very thick \begin{tikzpicture} \filldraw[white] (0,0) rectangle (1em,1.5ex); \draw[very thick] (0,0.7ex) -- (1em,0.7ex);\end{tikzpicture},
ultra thick \begin{tikzpicture} \filldraw[white] (0,0) rectangle (1em,1.5ex); \draw[ultra thick] (0,0.7ex) -- (1em,0.7ex);\end{tikzpicture}.\\
Note: \verb![help lines]=[gray,very thin]!. Line thickness can be also specified by\\ \verb![line width]! option, say \verb![line width=0.5cm]!.
\item line type:
loosely dashed \begin{tikzpicture} \filldraw[white] (0,0) rectangle (1em,1.5ex); \draw[loosely dashed] (0,0.7ex) -- (1em,0.7ex);\end{tikzpicture},
dashed \begin{tikzpicture} \filldraw[white] (0,0) rectangle (1em,1.5ex); \draw[dashed] (0,0.7ex) -- (1em,0.7ex);\end{tikzpicture},
densely dashed \begin{tikzpicture} \filldraw[white] (0,0) rectangle (1em,1.5ex); \draw[densely dashed] (0,0.7ex) -- (1em,0.7ex);\end{tikzpicture},
loosely dotted \begin{tikzpicture} \filldraw[white] (0,0) rectangle (1em,1.5ex); \draw[loosely dotted] (0,0.7ex) -- (1em,0.7ex);\end{tikzpicture},
dotted \begin{tikzpicture} \filldraw[white] (0,0) rectangle (1em,1.5ex); \draw[dotted] (0,0.7ex) -- (1em,0.7ex);\end{tikzpicture},
densely dotted \begin{tikzpicture} \filldraw[white] (0,0) rectangle (1em,1.5ex); \draw[densely dotted] (0,0.7ex) -- (1em,0.7ex);\end{tikzpicture}.
\item arrow:
\verb!<-! \begin{tikzpicture} \filldraw[white] (0,0) rectangle (1em,1.5ex); \draw[<-] (0,0.7ex) -- (1em,0.7ex);\end{tikzpicture},
\verb!<<-! \begin{tikzpicture} \filldraw[white] (0,0) rectangle (1em,1.5ex); \draw[<<-] (0,0.7ex) -- (1em,0.7ex);\end{tikzpicture},
\verb!<-|! \begin{tikzpicture} \filldraw[white] (0,0) rectangle (1em,1.5ex); \draw[<-|] (0,0.7ex) -- (1em,0.7ex);\end{tikzpicture},
\verb!<<-|! \begin{tikzpicture} \filldraw[white] (0,0) rectangle (1em,1.5ex); \draw[<<-|] (0,0.7ex) -- (1em,0.7ex);\end{tikzpicture},
\verb!->! \begin{tikzpicture} \filldraw[white] (0,0) rectangle (1em,1.5ex); \draw[->] (0,0.7ex) -- (1em,0.7ex);\end{tikzpicture},
\verb!->>! \begin{tikzpicture} \filldraw[white] (0,0) rectangle (1em,1.5ex); \draw[->>] (0,0.7ex) -- (1em,0.7ex);\end{tikzpicture},
\verb!|->! \begin{tikzpicture} \filldraw[white] (0,0) rectangle (1em,1.5ex); \draw[|->] (0,0.7ex) -- (1em,0.7ex);\end{tikzpicture},
\verb!|->>! \begin{tikzpicture} \filldraw[white] (0,0) rectangle (1em,1.5ex); \draw[|->>] (0,0.7ex) -- (1em,0.7ex);\end{tikzpicture},
\verb!<->! \begin{tikzpicture} \filldraw[white] (0,0) rectangle (1em,1.5ex); \draw[<->] (0,0.7ex) -- (1em,0.7ex);\end{tikzpicture},
\verb!<<->>! \begin{tikzpicture} \filldraw[white] (0,0) rectangle (1em,1.5ex); \draw[<<->>] (0,0.7ex) -- (1em,0.7ex);\end{tikzpicture}.\\
Note: You can also add \verb!>=stealth! in the options, which changes the arrow to 'stealth-like' style.
\end{itemize}
\begin{verbatim}
Usage:
\draw[color, thickness, line type, arrow] (x1,y1) -- (x2,y2);
Example:
\begin{tikzpicture}
\draw[red, very thin, densely dashed, <-] (0,0) -- (0.9,0);
\draw[green, ultra thick, loosely dotted, |->] (1.1,0) -- (1.9,0);
\draw[blue, semithick, <->, >=stealth] (2.1,0) -- (2.9,0);
\draw[purple, line width=0.3cm] (3.1,0) -- (3.9,0);
\end{tikzpicture}
\end{verbatim}
\begin{tikzpicture}
\draw[red, very thin, densely dashed, <-] (0,0) -- (0.9,0);
\draw[green, ultra thick, loosely dotted, |->] (1.1,0) -- (1.9,0);
\draw[blue, semithick, <->, >=stealth] (2.1,0) -- (2.9,0);
\draw[purple, line width=0.3cm] (3.1,0) -- (3.9,0);
\end{tikzpicture}
\section{Arc Path Construction}
\begin{verbatim}
Usage:
\draw (x,y) arc (angle1:angle2:radius);
\draw (x,y) arc [start angle=angle1, end angle=angle2, radius=radius];
\draw (x,y) arc (angle1:angle2:x.radius and y.radius);
\draw (x,y) arc [start angle=angle1, end angle=angle2, x radius=rx, y radius=ry]
Example:
\begin{tikzpicture}
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
\draw (0.5,0) arc (0:120:0.5cm);
\draw (1,0) arc (0:315:1.75cm and 1cm);
\draw (-1,0) arc [start angle=180, end angle=120, radius=0.5cm];
% The above is not a recommand way.
\end{tikzpicture}
\end{verbatim}
\begin{tikzpicture}
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
\draw (0.5,0) arc (0:120:0.5cm);
\draw (1,0) arc (0:315:1.75cm and 1cm);
\draw (-1,0) arc [start angle=180, end angle=120, radius=0.5cm];
\end{tikzpicture}
\section{Adding a Touch Style}
\noindent
\textsf{Styles} are predefined sets of options that can be used to organize how a graphic is drawn. To define a style globally, we can use the \textbackslash tikzset command at the beginning of the document.
\begin{verbatim}
Usage:
\tikzset{style_name./style={options}}
Example:
\tikzset{blue_thin_lines/.style={color=blue!50,very thin}}
\begin{tikzpicture}
\draw[blue_thin_lines] (0,0) grid (5,5);
\end{tikzpicture}
\end{verbatim}
\tikzset{blue_thin_lines/.style={color=blue!50,very thin}}
\begin{tikzpicture}
\draw[step=0.5cm, blue_thin_lines] (0,0) grid (2,2);
\end{tikzpicture}\\
\noindent To define a style locally, we use a pair of square bracket ``[ ]'' to define styles at the beginning of a picture.
\begin{verbatim}
Usage:
[style_name/.style={options}]
Example:
\begin{tikzpicture}
[red_thick_lines/.style={color=red!50,very thick}];
\draw[step=0.5cm, red_thick_lines] (0,0) grid (2,2);
\end{tikzpicture}
\end{verbatim}
\begin{tikzpicture}
[red_thick_lines/.style={color=red!50,very thick}]
\draw[step=0.5cm, red_thick_lines] (0,0) grid (2,2);
\end{tikzpicture}\\
\noindent One can also define styles hierarchically.
\begin{verbatim}
Usage:
\tikzset{style_name1/.style={style_name2, options}}
Example:
\tikzset{green_help_lines/.style={help lines, color=green!90}}
\begin{tikzpicture}
\draw[step=0.5cm, green_help_lines] (0,0) grid (5,5);
\end{tikzpicture}
\end{verbatim}
\tikzset{green_help_lines/.style={help lines, color=green!90, ultra thick}}
\begin{tikzpicture}
\draw[step=0.5cm, help lines] (0,0) grid (2,2);
\draw[step=0.5cm, green_help_lines] (2,0) grid (4,2);
\end{tikzpicture}\\
\noindent Styles can also be used with a parameter.
\begin{verbatim}
Usage:
[style_name/.style={options}, style_name/.default={options}]
Example:
\begin{tikzpicture}
[para_color/.style={help lines,color=#1!50}, para_color/.default=blue]
\draw[step=0.5cm, para_color] (0,0) grid (2,2);
\draw[step=0.5cm, para_color=red] (2,0) grid (4,2);
\end{tikzpicture}
\end{verbatim}
\begin{tikzpicture}
[para_color/.style={help lines,color=#1!50}, para_color/.default=blue]
\draw[step=0.5cm, para_color] (0,0) grid (2,2);
\draw[step=0.5cm, para_color=red] (2,0) grid (4,2);
\end{tikzpicture}
\section{Clipping a Path}
\noindent The \textbackslash clip command clip all subsequent drawing.
\begin{verbatim}
Usage:
\clip[options] (x1,y1) rectangle (x2,y2);
Example:
\begin{tikzpicture}[scale=3]
\clip (-0.1,-0.2) rectangle (1.1,0.75);
\draw[step=.5cm, help lines] (-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);
\end{tikzpicture}
\end{verbatim}
\begin{tikzpicture}[scale=3]
\clip (-0.1,-0.2) rectangle (1.1,0.75);
\draw[step=.5cm, help lines] (-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);
\end{tikzpicture}
\begin{verbatim}
Usage:
\clip (x1,y1) circle (radius);
Example:
\begin{tikzpicture}[scale=3]
\clip[draw] (0.5,0.5) circle (.6cm);
\draw[step=.5cm, help lines] (-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);
\end{tikzpicture}
\end{verbatim}
\begin{tikzpicture}[scale=3]
\clip[draw] (0.5,0.5) circle (.6cm);
\draw[step=.5cm, help lines] (-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);
\end{tikzpicture}
\section{Parabola Path Construction}
\begin{verbatim}
Usage:
\draw[options] (x1,y1) parabola (x2,y2);
Example:
\begin{tikzpicture}[scale=3]
\draw (0,0) rectangle (1,1) (0,0) parabola (1,1);
\end{tikzpicture}
\end{verbatim}
\begin{tikzpicture}
\draw (0,0) rectangle (2,2) (0,0) parabola (2,2);
\end{tikzpicture}
\begin{verbatim}
Usage:
\draw[options] (x1,y1) parabola bend (x2,y2) (x3,y3);
Example:
\begin{tikzpicture}
\draw[x=0.2cm,y=0.2cm] (0,0) parabola bend (4,10) (6,6);
\end{tikzpicture}
\end{verbatim}
\begin{tikzpicture}
\draw[x=0.2cm,y=0.2cm] (0,0) parabola bend (4,10) (6,6);
\end{tikzpicture}
\section{Sine and Cosine Path Construction}
\begin{verbatim}
Usage:
\draw[options] (x1,y1) sin (x2,y2);
\draw[options] (x1,y1) cos (x2,y2);
Example:
\begin{tikzpicture}
\draw[help lines] (-0.5,-1.5) grid (4.5,1.5);
\draw[red] (0,0) sin (1,1) cos (2,0) sin (3,-1) cos (4,0);
\draw[blue] (0,1) cos (1,0) sin (2,-1) cos (3,0) sin (4,1);
\end{tikzpicture}
\end{verbatim}
\begin{tikzpicture}
\draw[help lines] (-0.5,-1.5) grid (4.5,1.5);
\draw[red] (0,0) sin (1,1) cos (2,0) sin (3,-1) cos (4,0);
\draw[blue] (0,1) cos (1,0) sin (2,-1) cos (3,0) sin (4,1);
\end{tikzpicture}
\section{Filling and Drawing}
\begin{verbatim}
Usage:
\fill[options] (x1,y1) -- (x2,y2) arc (angle1:angle2:radius) -- (x3,y3);
\fill[options] (x1,y1) -- (x2,y2) arc (angle1:angle2:radius) -- cycle; % better
\filldraw[options] (x1,y1) -- (x2,y2) arc (angle1:angle2:radius) -- cycle;
Example:
\begin{tikzpicture}[line width=5pt]
\fill[blue!80] (0,0) -- (3,0) arc (0:30:2) -- (0,0);
\draw (4,0) -- (5,0) -- (5,1) -- (4,0);
\draw (6,0) -- (7,0) -- (7,1) -- cycle;
\filldraw[fill=green!20!white, draw=green!50!black]
(8,0) -- (11,0) arc (0:45:3) -- cycle;
\end{tikzpicture}
\end{verbatim}
\begin{tikzpicture}[line width=5pt]
\fill[blue!80] (0,0) -- (3,0) arc (0:30:2) -- (0,0);
\draw (4,0) -- (5,0) -- (5,1) -- (4,0);
\draw (6,0) -- (7,0) -- (7,1) -- cycle;
\filldraw[fill=green!20!white, draw=green!50!black]
(8,0) -- (11,0) arc (0:45:3) -- cycle;
\end{tikzpicture}
\section{Shading}
\begin{verbatim}
Usage:
\shade[options] (x1,y1) rectangle (x2,y2);
\shadedraw[options] (x1,y1) circle (radius);
Example:
\begin{tikzpicture}[rounded corners,ultra thick]
\shade (0,0) rectangle (2,1);
\shadedraw (3,0.5) circle (.5cm);
\shade[top color=yellow,bottom color=black] (0,0) rectangle +(2,1);
\shade[left color=yellow,right color=black] (3,0) rectangle +(2,1);
\shadedraw[inner color=yellow,outer color=black,draw=yellow]
(6,0) rectangle +(2,1);
\shade[ball color=green] (9,.5) circle (.5cm);
\shadedraw[left color=gray,right color=green, draw=green!50!black]
(10,0.3) -- +(1,0) arc (0:30:1) -- cycle;
\end{tikzpicture}
\end{verbatim}
\begin{tikzpicture}[rounded corners,ultra thick]
\shade (0,0) rectangle (2,1);
\shadedraw (3,0.5) circle (.5cm);
\shade[top color=yellow,bottom color=black] (4,0) rectangle +(2,1);
\shade[left color=yellow,right color=black] (7,0) rectangle +(2,1);
\shadedraw[inner color=yellow,outer color=black,draw=yellow] (10,0) rectangle +(2,1);
\shade[ball color=green] (13,.5) circle (.5cm);
\shadedraw[left color=gray,right color=green, draw=green!50!black]
(14,0.3) -- +(1,0) arc (0:30:1) -- cycle;
\end{tikzpicture}
\section{Specifying Coordinates}
\begin{verbatim}
Usage:
(xpt,ycm): xpt in x-direction and ycm in y-directions.
(xdegree:ycm): ycm in direction x degree.
+(x,y): xcm above and ycm right from the previous specified position.
++(x,y): xcm above and ycm right from the previous specified position
and making this the new specified position.
(x1,y1) -- (x2,y2): straight line from (x1,y1) to (x2,y2);
(x1,y1) -| (x2,y2): a horizontal and vertical line from (x1,y1) to (x2,y2);
(x1,y1) |- (x2,y2); a vertical and horizontal line from (x1,y1) to (x2,y2);
Example:
\begin{tikzpicture}
\draw[red,very thick] (30:1cm) -- (0,0);
\draw[blue,very thick] (0,0) -| +(1.5,0.5) ;
\draw[green,very thick] (0,0) |- ++(0,1) -- (1,0);
\end{tikzpicture}
\end{verbatim}
\begin{tikzpicture}
\draw[red,very thick] (30:1cm) -- (0,0);
\draw[blue,very thick] (0,0) -| +(1.5,0.5) ;
\draw[green,very thick] (0,0) ++(0,1) -- (1,0);
\end{tikzpicture}
\section{Scoping}
\begin{verbatim}
Usage:
\begin{scope}[options]
% only apply graphic options inside this scope, but not to anything outside.
\end{scope}
Example:
\begin{tikzpicture}[ultra thick]
\draw (0,0) -- (0,1);
\begin{scope}[thin]
\draw (1,0) -- (1,1);
\end{scope}
\draw (2,0) -- (2,1);
\end{tikzpicture}
\end{verbatim}
\begin{tikzpicture}[ultra thick]
\draw (0,0) -- (0,1);
\begin{scope}[thin]
\draw (1,0) -- (1,1);
\end{scope}
\draw (2,0) -- (2,1);
\end{tikzpicture}
\section{Transformations}
\begin{verbatim}
Usage:
[xshift=x,yshift=y]: allows you to shift all subsequent points by x and y amount.
[shift={(x,y)}] or [shift={+(x,y)}];
[rotate=angle]: rotating by a certain angle.
[rotate around={angle:(x,y)}]: rotating around a given point by a certain angle.
[xscale=unit1,yscale=unit2]: scaling the x-direction or y-direction.
[scale=unit]: scaling by a certain factor
[xslant=unit1,yslant=unit2]: slanting the x-direction or y-direction.
Example:
\begin{tikzpicture}
\draw[help lines, step=0.5] (0,0) grid (7,1.5);
\draw[red, very thick] (0,0) -- (0,0.5)
[shift={(4pt,2pt)}] (0,0) -- (0,0.5);
\draw[red, very thick] (0.5,0) -- (0.5,0.5)
[shift={+(4pt,2pt)}] (0.5,0) -- (0.5,0.5);
\draw[rotate=30,fill=blue] (1.5,-1) rectangle (2,-0.5);
\draw[rotate around={60:(3,0.5)},fill=blue] (2.5,0.25) rectangle (3,0.75);
\draw[xscale=1,yscale=1.1,fill=green] (4,0.5) circle (0.5);
\draw[xslant=2,very thick] (5,0) -- (5.5,0.5) -- (5.5,0);
\end{tikzpicture}
\end{verbatim}
\begin{tikzpicture}
\draw[help lines, step=0.5] (0,0) grid (7,1.5);
\draw[red, very thick] (0,0) -- (0,0.5)
[shift={(4pt,2pt)}] (0,0) -- (0,0.5);
\draw[red, very thick] (0.5,0) -- (0.5,0.5)
[shift={+(4pt,2pt)}] (0.5,0) -- (0.5,0.5);
\draw[rotate=30,fill=blue] (1.5,-1) rectangle (2,-0.5);
\draw[rotate around={60:(3,0.5)},fill=blue] (2.5,0.25) rectangle (3,0.75);
\draw[xscale=1,yscale=1.1,fill=green] (4,0.5) circle (0.5);
\draw[xslant=2,very thick] (5,0) -- (5.5,0.5) -- (5.5,0);
\end{tikzpicture}
\begin{verbatim}
\begin{tikzpicture}
\filldraw[fill=red] (0,0) rectangle (1,1)
[xshift=5pt,yshift=5pt] (0,0) rectangle (1,1)
[rotate=30] (-1,-1) rectangle (2,2);
\end{tikzpicture}
\end{verbatim}
\begin{tikzpicture}[even odd rule,rounded corners=2pt,x=10pt,y=10pt]
\filldraw[fill=red] (0,0) rectangle (1,1)
[xshift=5pt,yshift=5pt] (0,0) rectangle (1,1)
[rotate=30] (-1,-1) rectangle (2,2);
\end{tikzpicture}
\section{For-Loops}
\begin{verbatim}
Usage:
\foreach \variable in {list of values}{
\commands ;
}
Example:
\begin{tikzpicture}
\foreach \x in {-0.5cm,0cm,0.5cm}{
\draw[red,very thick] (\x,-5pt) -- (\x,5pt);
}
\foreach \y in {-0.5cm,0cm,0.5cm}{
\draw[blue,very thick] (1cm,\y) -- (1.5cm,\y);
}
\foreach \x in {0,...,9}{
\draw[green,very thick] (\x,-1) circle (0.4cm);
}
\foreach \x in {2,2.5,...,4}{
\draw[purple,very thick] (\x cm,-3pt) -- (\x cm,3pt);
}
\end{tikzpicture}
\end{verbatim}
\begin{tikzpicture}
\foreach \x in {-0.5cm,0cm,0.5cm}{
\draw[red,very thick] (\x,-5pt) -- (\x,5pt);
}
\foreach \y in {-0.5cm,0cm,0.5cm}{
\draw[blue,very thick] (1cm,\y) -- (1.5cm,\y);
}
\foreach \x in {0,...,9}{
\draw[green,very thick] (\x,-1) circle (0.4cm);
}
\foreach \x in {2,2.5,...,4}{
\draw[purple,very thick] (\x cm,-3pt) -- (\x cm,3pt);
}
\end{tikzpicture}
\begin{verbatim}
\begin{tikzpicture}
\foreach \x in {1,2,...,5,7,8,...,12}{
\foreach \y in {1,...,5}{
\draw (\x,\y) +(-0.5,-0.5) rectangle +(0.5,0.5);
\draw (\x,\y) node{\x,\y};
}
}
\end{tikzpicture}
\end{verbatim}
\begin{tikzpicture}
\foreach \x in {1,2,...,5,7,8,...,12}{
\foreach \y in {1,...,5}{
\draw (\x,\y) +(-0.5,-0.5) rectangle +(0.5,0.5);
\draw (\x,\y) node{\x,\y};
}
}
\end{tikzpicture}
% \begin{tikzpicture}
% \foreach \x in {-1cm,-0.5cm,1cm}
% \foreach \x in {1,2,3} {$x=\x, $}
% \end{tikzpicture}
\section{Adding Text}
\begin{verbatim}
Usage:
\draw (x,y) node[options] {text};
\draw (x,y) node[options] {text};
\node[options] at (x,y) {text};
options: above,below,left,right, or anchor=north,south,west,east.
Example:
\begin{tikzpicture}[scale=2]
\draw[<->] (0,1) -- (0,0) -- (1,0);
\draw[fill] (0.5,0.5) circle (0.05);
\draw (0.5,0.5) node[above=10pt] {A} node[left=10pt] {L}
node[below=10pt] {B} node[right=10pt] {R};
\draw (0.5,0.5) node[above left=2pt] {AL} node[below left=2pt] {BL}
node[below right=2pt] {BR} node[above right=2pt] {AR};
\end{tikzpicture}
\begin{tikzpicture}[scale=2]
\draw[<->] (0,1) -- (0,0) -- (1,0);
\draw[fill] (0.5,0.5) circle (0.05);
\draw (0.5,0.5) node[anchor=north] {N} node[anchor=west] {W}
node[anchor=south] {S} node[anchor=east] {E};
\draw (0.5,0.5) node[anchor=north west] {NW} node[anchor=south west] {SW}
node[anchor=south east] {SE} node[anchor=north east] {NE};
\end{tikzpicture}
\end{verbatim}
\begin{tikzpicture}[scale=2]
\draw[<->] (0,1) -- (0,0) -- (1,0);
\draw[fill] (0.5,0.5) circle (0.05);
\draw (0.5,0.5) node[above=10pt] {A} node[left=10pt] {L} node[below=10pt] {B} node[right=10pt] {R};
\draw (0.5,0.5) node[above left=2pt] {AL} node[below left=2pt] {BL} node[below right=2pt] {BR} node[above right=2pt] {AR};
\end{tikzpicture}
\begin{tikzpicture}[scale=2]
\draw[<->] (0,1) -- (0,0) -- (1,0);
\draw[fill] (0.5,0.5) circle (0.05);
\draw (0.5,0.5) node[anchor=north] {N} node[anchor=west] {W} node[anchor=south] {S} node[anchor=east] {E};
\draw (0.5,0.5) node[anchor=north west] {NW} node[anchor=south west] {SW} node[anchor=south east] {SE} node[anchor=north east] {NE};
\end{tikzpicture}
\begin{verbatim}
\begin{tikzpicture}
\draw (0,0) .. controls (6,1) and (9,1) ..
node[near start,sloped,above] {near start}
node {midway}
node[very near end,sloped,below] {very near end} (12,0);
\end{tikzpicture}
\end{verbatim}
\begin{tikzpicture}
\draw (0,0) .. controls (6,1) and (9,1) ..
node[near start,sloped,above] {near start}
node {midway}
node[very near end,sloped,below] {very near end} (12,0);
\end{tikzpicture}
\begin{verbatim}[scale=1.5]
\begin{tikzpicture}
\draw (0,0) node(a) [draw,align=center] {This is a test\\$a$ node}
(1,1) node(b) [draw] {Node B};
\draw (a.north) |- (b.west);
\draw[color=red] (a.east) -| (2,1.5) -| (b.north);
\end{tikzpicture}
\end{verbatim}
\begin{tikzpicture}[scale=1.5]
\draw (0,0) node(a) [draw,align=center] {This is a test\\$a$ node} (1,1) node(b) [draw] {Node B};
\draw (a.north) |- (b.west);
\draw[color=red] (a.east) -| (2,1.5) -| (b.north);
\end{tikzpicture}
\section{Coordinate}
\begin{verbatim}
Useage:
\coordinate (name) at (x,y);
Example:
\begin{tikzpicture}
\coordinate (A) at (1,0);
\coordinate (B) at (0,0);
\coordinate (C) at (30:1cm);
\draw (A) -- (B) -- (C);
\end{tikzpicture}
\end{verbatim}
\begin{tikzpicture}
\coordinate (A) at (1,0);
\coordinate (B) at (0,0);
\coordinate (C) at (30:1cm);
\draw (A) node[below right] {$A$} -- (B) node[below left] {$B$} -- (C) node[above right] {$C$};
\end{tikzpicture}
\section{Trangency}
\begin{verbatim}
Usage:
\draw (x1,y1) to [out=degree1,in=degree2] (x2,y2);
Example:
\begin{tikzpicture}
\draw [help lines] (0,0) grid (4,4);
\draw [<->] (5,0) -- (0,0) -- (0,5);
\draw (3,0) -- (0,3);
\draw [dashed, ultra thick] (0.5,3.5) to [out=280,in=135] (1.5,1.5);
\draw [dashed, ultra thick] (1.5,1.5) to [out=315,in=170] (3.5,0.5);
\end{tikzpicture}
\end{verbatim}
\begin{tikzpicture}
\draw [help lines] (0,0) grid (4,4);
\draw [<->] (5,0) -- (0,0) -- (0,5);
\draw (3,0) -- (0,3);
\draw [dashed, ultra thick] (0.5,3.5) to [out=280,in=135] (1.5,1.5);
\draw [dashed, ultra thick] (1.5,1.5) to [out=315,in=170] (3.5,0.5);
\end{tikzpicture}
\end{document}