1% tikz_shapes.tex
2% Basic TikZ shapes, colors, fills, and node labels
3% Demonstrates fundamental drawing commands in TikZ
4
5\documentclass[12pt,a4paper]{article}
6
7\usepackage{tikz}
8\usepackage[margin=1in]{geometry}
9\usepackage{amsmath}
10
11% TikZ libraries for advanced features
12\usetikzlibrary{shapes.geometric, arrows.meta, positioning, patterns, decorations.pathmorphing}
13
14\title{TikZ Basic Shapes and Drawing}
15\author{LaTeX Student}
16\date{\today}
17
18\begin{document}
19
20\maketitle
21
22\section{Lines and Basic Shapes}
23
24\subsection{Lines and Paths}
25
26\begin{center}
27\begin{tikzpicture}[scale=1.5]
28 % Simple line
29 \draw (0,0) -- (3,0);
30 \node[below] at (1.5,-0.1) {Straight line};
31
32 % Line with multiple points
33 \draw[thick, blue] (0,1) -- (1,2) -- (2,1) -- (3,2);
34 \node[above] at (1.5,2.1) {Polyline (thick, blue)};
35
36 % Dashed and dotted lines
37 \draw[dashed, red] (0,3) -- (3,3);
38 \node[right] at (3,3) {Dashed line};
39
40 \draw[dotted, green!70!black, thick] (0,3.5) -- (3,3.5);
41 \node[right] at (3,3.5) {Dotted line};
42
43 % Line with arrow
44 \draw[->, >=Stealth, ultra thick] (0,4.5) -- (3,4.5);
45 \node[right] at (3,4.5) {Arrow};
46
47 % Double arrow
48 \draw[<->, >=Latex] (0,5) -- (3,5);
49 \node[right] at (3,5) {Double arrow};
50\end{tikzpicture}
51\end{center}
52
53\subsection{Circles and Ellipses}
54
55\begin{center}
56\begin{tikzpicture}
57 % Basic circle
58 \draw (0,0) circle (1cm);
59 \node at (0,-1.5) {Circle (1cm)};
60
61 % Filled circle
62 \draw[fill=blue!30] (3,0) circle (0.8cm);
63 \node at (3,-1.5) {Filled circle};
64
65 % Circle with colored border
66 \draw[draw=red, fill=yellow!40, thick] (6,0) circle (0.8cm);
67 \node at (6,-1.5) {Colored border};
68
69 % Ellipse
70 \draw[fill=green!20] (9,0) ellipse (1.2cm and 0.6cm);
71 \node at (9,-1.5) {Ellipse};
72\end{tikzpicture}
73\end{center}
74
75\subsection{Rectangles and Squares}
76
77\begin{center}
78\begin{tikzpicture}
79 % Basic rectangle
80 \draw (0,0) rectangle (2,1.5);
81 \node at (1,0.75) {Rectangle};
82
83 % Filled rectangle
84 \draw[fill=orange!40] (3,0) rectangle (5,1.5);
85 \node at (4,0.75) {Filled};
86
87 % Rectangle with rounded corners
88 \draw[fill=purple!30, rounded corners=5pt] (6,0) rectangle (8,1.5);
89 \node at (7,0.75) {Rounded};
90
91 % Square with thick border
92 \draw[ultra thick, draw=blue!70] (9,0) rectangle (10.5,1.5);
93 \node at (9.75,0.75) {Thick};
94\end{tikzpicture}
95\end{center}
96
97\section{Arcs and Curves}
98
99\subsection{Arcs}
100
101\begin{center}
102\begin{tikzpicture}[scale=1.2]
103 % Basic arc
104 \draw (0,0) arc (0:90:2cm);
105 \node at (0,-0.5) {Arc 0°--90°};
106
107 % Arc with different angles
108 \draw[thick, red] (3,0) arc (0:180:1.5cm);
109 \node at (3,-0.5) {Arc 0°--180°};
110
111 % Full circle using arc
112 \draw[blue, dashed] (7,0) arc (0:360:1cm);
113 \node at (7,-0.5) {Arc 360°};
114\end{tikzpicture}
115\end{center}
116
117\subsection{Bézier Curves}
118
119\begin{center}
120\begin{tikzpicture}
121 % Quadratic Bézier curve
122 \draw[thick] (0,0) .. controls (1,2) .. (2,0);
123 \draw[dashed, gray] (0,0) -- (1,2) -- (2,0);
124 \fill (0,0) circle (2pt) node[below] {Start};
125 \fill (1,2) circle (2pt) node[above] {Control};
126 \fill (2,0) circle (2pt) node[below] {End};
127
128 % Cubic Bézier curve
129 \begin{scope}[xshift=4cm]
130 \draw[thick, blue] (0,0) .. controls (0.5,2) and (1.5,2) .. (2,0);
131 \draw[dashed, gray] (0,0) -- (0.5,2) -- (1.5,2) -- (2,0);
132 \fill (0,0) circle (2pt);
133 \fill (0.5,2) circle (2pt) node[above] {C1};
134 \fill (1.5,2) circle (2pt) node[above] {C2};
135 \fill (2,0) circle (2pt);
136 \end{scope}
137\end{tikzpicture}
138\end{center}
139
140\section{Node Labels and Positioning}
141
142\begin{center}
143\begin{tikzpicture}[scale=1.5]
144 % Nodes with different positions
145 \draw[thick, ->] (0,0) -- (4,0) node[right] {$x$};
146 \draw[thick, ->] (0,0) -- (0,3) node[above] {$y$};
147
148 % Labeled points
149 \fill (1,1) circle (2pt) node[above right] {$A(1,1)$};
150 \fill (3,2) circle (2pt) node[above right] {$B(3,2)$};
151 \fill (2,2.5) circle (2pt) node[above] {$C(2,2.5)$};
152
153 % Line with midpoint label
154 \draw[thick, blue] (1,1) -- (3,2) node[midway, below, sloped] {Distance $d$};
155
156 % Nodes with boxes
157 \node[draw, rectangle, fill=yellow!20] at (2,0.5) {Boxed label};
158 \node[draw, circle, fill=red!20] at (3.5,1.5) {Circle};
159\end{tikzpicture}
160\end{center}
161
162\section{Colors and Fills}
163
164\subsection{Color Mixing}
165
166\begin{center}
167\begin{tikzpicture}
168 % Different color intensities
169 \foreach \i in {10,20,...,100} {
170 \fill[blue!\i] (\i/20,0) rectangle ++(0.5,1);
171 }
172 \node at (3,-0.5) {Blue intensity 10\% to 100\%};
173
174 % Color mixing
175 \begin{scope}[yshift=-2cm]
176 \fill[red!70!blue] (0,0) rectangle (1,1);
177 \node at (0.5,-0.5) {70\% red, 30\% blue};
178
179 \fill[green!50!yellow] (2,0) rectangle (3,1);
180 \node at (2.5,-0.5) {50\% green, 50\% yellow};
181
182 \fill[blue!40!white] (4,0) rectangle (5,1);
183 \node at (4.5,-0.5) {40\% blue, 60\% white};
184 \end{scope}
185\end{tikzpicture}
186\end{center}
187
188\subsection{Patterns and Fills}
189
190\begin{center}
191\begin{tikzpicture}
192 % Solid fills
193 \draw[fill=cyan!30] (0,0) rectangle (1.5,1.5);
194 \node at (0.75,0.75) {Solid};
195
196 % Pattern fills
197 \draw[pattern=dots, pattern color=blue] (2,0) rectangle (3.5,1.5);
198 \node at (2.75,0.75) {Dots};
199
200 \draw[pattern=north east lines, pattern color=red] (4,0) rectangle (5.5,1.5);
201 \node at (4.75,0.75) {Lines};
202
203 \draw[pattern=crosshatch, pattern color=green!70!black] (6,0) rectangle (7.5,1.5);
204 \node at (6.75,0.75) {Crosshatch};
205\end{tikzpicture}
206\end{center}
207
208\section{Complex Example: Geometric Shapes}
209
210\begin{center}
211\begin{tikzpicture}[scale=1.2]
212 % Draw a house
213 \draw[thick, fill=brown!30] (0,0) rectangle (3,2); % House body
214 \draw[thick, fill=red!50] (0,2) -- (1.5,3.5) -- (3,2) -- cycle; % Roof
215 \draw[thick, fill=blue!20] (0.5,0.3) rectangle (1.2,1.3); % Door
216 \draw[thick, fill=yellow!30] (1.8,1.2) rectangle (2.5,1.8); % Window
217 \draw (1.8,1.5) -- (2.5,1.5); % Window cross
218 \draw (2.15,1.2) -- (2.15,1.8);
219
220 % Sun
221 \draw[fill=yellow] (6,3) circle (0.4cm);
222 \foreach \angle in {0,45,...,315} {
223 \draw[thick, yellow] (6,3) -- ++(\angle:0.6cm);
224 }
225
226 % Tree
227 \draw[thick, fill=brown!70] (5,0) rectangle (5.3,1.2); % Trunk
228 \draw[thick, fill=green!60!black] (5.15,1.2) circle (0.6cm); % Leaves
229
230 % Ground
231 \draw[thick, green!50!black, fill=green!30] (-0.5,-0.2) rectangle (7,0);
232
233 % Labels
234 \node[below] at (1.5,-0.2) {\textbf{House}};
235 \node[below] at (5.15,-0.2) {\textbf{Tree}};
236\end{tikzpicture}
237\end{center}
238
239\section{Compilation Notes}
240
241To compile this document:
242\begin{verbatim}
243pdflatex tikz_shapes.tex
244\end{verbatim}
245
246TikZ is processed during the LaTeX compilation, so no additional steps are needed.
247
248\end{document}