├── .gitignore ├── variables.tex ├── minimal.tex ├── plot.tex ├── 1dmesh.tex ├── main.tex ├── preamble.tex ├── conditional-plot.tex ├── nodes.tex ├── interline.tex ├── PIP.tex ├── tut-1.tex ├── shorten-bug.tex ├── alignment_issue.tex ├── coolwarm-colormap.tex ├── grid.tex ├── annotated-equations.tex ├── tut-5.tex └── tut-3.tex /.gitignore: -------------------------------------------------------------------------------- 1 | # Mac shit 2 | .DS_Store 3 | 4 | # Output 5 | *.pdf 6 | *.aux 7 | *.log 8 | *.gz 9 | *.toc 10 | 11 | # Vim shit 12 | *.sw? 13 | -------------------------------------------------------------------------------- /variables.tex: -------------------------------------------------------------------------------- 1 | \documentclass{standalone}\usepackage{tikz}\begin{document} 2 | \def\a{5} 3 | \texttt{print(a = \a)} 4 | 5 | \begin{tikzpicture} 6 | \def\a{7} 7 | \node (0, 0) {Inside TikZ a = \a.}; 8 | \end{tikzpicture} 9 | 10 | Finally, outside a = \a. 11 | \end{document} -------------------------------------------------------------------------------- /minimal.tex: -------------------------------------------------------------------------------- 1 | \documentclass{standalone} 2 | \usepackage{tikz} 3 | \begin{document} 4 | \fbox{Before \tikz[baseline=-2pt]{\draw[->] (0,0) -- (2,0) node [midway, anchor=south] {time};} after.} 5 | % \fbox{Before \tikz[baseline=-3pt]{\draw[->] (0,0) -- (1,0) node [anchor=west] {test};} after.} 6 | \end{document} -------------------------------------------------------------------------------- /plot.tex: -------------------------------------------------------------------------------- 1 | \vspace{1ex} 2 | \begin{tikzpicture} 3 | \begin{axis}[width=5cm] 4 | \pgfplotsset{ 5 | every axis plot post/.style={domain=0:360, samples=101, mark=none} 6 | } 7 | \ifA\addplot {sin(1*x)/1};\fi 8 | \ifB\addplot {sin(2*x)/2};\fi 9 | \ifC\addplot {sin(3*x)/3};\fi 10 | \end{axis} 11 | \end{tikzpicture} -------------------------------------------------------------------------------- /1dmesh.tex: -------------------------------------------------------------------------------- 1 | \documentclass{standalone} 2 | \usepackage{pgfplots}\pgfplotsset{compat=newest} 3 | \begin{document}\begin{tikzpicture}\begin{axis} 4 | \addplot [mesh,line width=20pt,domain=-1:1,samples=101] {sin(360*x)*x)}; 5 | \addplot [no marks,line width=20pt,domain=-1:1,samples=101] {sin(360*x)*x-1}; 6 | \end{axis}\end{tikzpicture}\end{document} -------------------------------------------------------------------------------- /main.tex: -------------------------------------------------------------------------------- 1 | \documentclass{article} 2 | \usepackage{tikz} 3 | \input{preamble} 4 | 5 | % Just for sake of my eyes… 6 | % \pagecolor{darkgray} 7 | % \color{white} 8 | 9 | \title{Learning TikZ} 10 | \author{Alfredo Canziani} 11 | \date{February 2022} 12 | 13 | \begin{document} 14 | 15 | \maketitle 16 | 17 | \input{tut-3} 18 | \input{tut-5} 19 | 20 | \end{document} 21 | -------------------------------------------------------------------------------- /preamble.tex: -------------------------------------------------------------------------------- 1 | 2 | \usetikzlibrary{positioning,shapes.misc} 3 | \tikzset{ 4 | terminal/.style={ 5 | rounded rectangle, 6 | minimum size=6mm, 7 | very thick,draw=black!50, 8 | top color=white,bottom color=black!20, 9 | font=\ttfamily, 10 | }, 11 | nonterminal/.style={ 12 | rectangle, 13 | minimum size=6mm, 14 | very thick, 15 | draw=red!50!black!50, 16 | top color=white, 17 | bottom color=red!50!black!20, 18 | font=\itshape, 19 | }, 20 | } -------------------------------------------------------------------------------- /conditional-plot.tex: -------------------------------------------------------------------------------- 1 | \documentclass{minimal} 2 | \usepackage{pgfplots} 3 | \begin{document} 4 | % Deactivate indentation 5 | \setlength{\parindent}{0pt} 6 | 7 | % Defining flags 8 | \newif\ifA\newif\ifB\newif\ifC 9 | 10 | % Activate A only 11 | Describing plot A. 12 | 13 | \Atrue\input{plot} % A 14 | 15 | % Activate also B 16 | Describing plot A \& B. 17 | 18 | \Btrue\input{plot} % A & B 19 | 20 | % Activate also C 21 | Describing plot A \& B \& C. 22 | 23 | \Ctrue\input{plot} % A & B & C 24 | \end{document} -------------------------------------------------------------------------------- /nodes.tex: -------------------------------------------------------------------------------- 1 | \documentclass[border=5mm]{standalone} 2 | \usepackage{tikz} 3 | \usetikzlibrary{positioning} 4 | \begin{document} 5 | \begin{tikzpicture}[ 6 | every node/.style={draw, rectangle, minimum size=5mm}, 7 | node distance=5mm, 8 | ] 9 | 10 | % \node (a) {a}; 11 | % \node (b) [right=of a] {b}; 12 | % \node (c) [red, above right=of a] {c}; 13 | % \node (c) [green, above right=5mm and 5mm of a] {c}; 14 | % \node (c) [blue, above right=5mm and 0mm of a] {c}; 15 | 16 | \node (a) {a}; 17 | \node (b) [above right=5mm and 5mm of a] {b}; 18 | % \node (c) at ((a) -| (b)) {c}; 19 | \path (a -| b) node {c}; 20 | 21 | 22 | \end{tikzpicture} 23 | \end{document} -------------------------------------------------------------------------------- /interline.tex: -------------------------------------------------------------------------------- 1 | \documentclass[border=5mm]{minimal} 2 | \usepackage{printlen}\usepackage{tikz} 3 | \showoutput 4 | \begin{document} 5 | \setlength{\parindent}{0pt} 6 | \newlength\h \h=\baselineskip 7 | 8 | \textcolor{cyan}{ 9 | Writing some\\ 10 | text over\\ 11 | multiple lines.} 12 | 13 | Writing some \tikz[baseline=\h/3]{ 14 | \draw (0,0) rectangle (\h,\h); 15 | \draw (0,0) rectangle (\h,\h/3); 16 | \draw (0,2/3*\h) rectangle ++(\h,\h/3); 17 | }\\ 18 | text over \tikz[baseline=\h/3]{\draw (0,0) rectangle (\h,\h);}\\ 19 | multiple lines. 20 | 21 | % Try \printlen{\ht\strutbox}. 22 | \newlength\mylen 23 | % \mylen = \ht\strutbox 24 | \settoheight{\mylen}{\strutbox} 25 | \the\mylen 26 | \end{document} -------------------------------------------------------------------------------- /PIP.tex: -------------------------------------------------------------------------------- 1 | \documentclass[a4paper]{article} 2 | \usepackage{pgfplots}\pgfplotsset{compat=newest} 3 | \usepackage[show frame]{geometry} 4 | \begin{document} 5 | \begin{figure}[t!]\centering 6 | \begin{tikzpicture}\begin{axis} 7 | \addplot+ [domain=0:360, samples=101, mark=none] {sin(x)}; 8 | \end{axis}\end{tikzpicture} 9 | \end{figure} 10 | \begin{figure}[t!]\centering 11 | \begin{tikzpicture}\begin{axis} 12 | \addplot+ [domain=0:360, samples=101, mark=none] {sin(x)}; 13 | \end{axis}\end{tikzpicture}\hskip -7cm 14 | \begin{tikzpicture}[baseline=-1cm]\begin{axis}[width=120pt] 15 | \addplot+ [domain=0:360, samples=101, mark=none] {sin(2*x)/2}; 16 | \end{axis}\end{tikzpicture} 17 | \end{figure} 18 | \begin{figure}[t!]\centering 19 | \begin{tikzpicture}\begin{axis} 20 | \addplot+ [domain=0:360, samples=101, mark=none] {sin(x)}; 21 | \end{axis}\begin{axis}[width=120pt, at={(8mm,6mm)}] 22 | \addplot+ [domain=0:360, samples=101, mark=none] {sin(2*x)/2}; 23 | \end{axis}\end{tikzpicture} 24 | \end{figure} 25 | \hfill % so the figures move up 26 | \end{document} -------------------------------------------------------------------------------- /tut-1.tex: -------------------------------------------------------------------------------- 1 | \documentclass[border=5mm]{standalone} 2 | \usepackage{tikz} 3 | \usetikzlibrary{intersections} 4 | \begin{document} 5 | % We're working on 6 | \begin{tikzpicture} [ 7 | scale = 3, 8 | ] 9 | \draw [ 10 | step = .5, 11 | gray, 12 | very thin, 13 | ] (-1.4, -1.4) grid (1.4, 1.4); 14 | \draw (-1.5, 0) -- (1.5, 0); 15 | \draw (0, -1.5) -- (0, 1.5); 16 | \draw (0, 0) circle [radius = 1]; 17 | \filldraw [fill = green!20!white, draw = green!50!black] (0, 0) -- (.3, 0) arc [start angle = 0, end angle = 30, radius = .3] -- cycle; 18 | \draw [red, very thick] (30:1) -- (30:1 |- 0,0); 19 | \draw [blue, very thick] (0, 0) -- (0,0 -| 30:1); 20 | 21 | % Drawing the tan as an intersection 22 | \path [name path = vert] (1, 0) -- (1, 1); 23 | \path [name path = 30deg] (0, 0) -- (30:1.5); 24 | \draw [name intersections = {of = vert and 30deg, by = t}, very thick, orange] (t) -- (1, 0); 25 | \filldraw [even odd rule] (0,0) rectangle (1,1) 26 | [xshift=5mm,yshift=5mm] (0,0) rectangle (1,1) 27 | [xshift=-1cm,yshift=-1cm,scale=2.5,rotate=10] (0,0) rectangle (1,1); 28 | \end{tikzpicture} 29 | \end{document} -------------------------------------------------------------------------------- /shorten-bug.tex: -------------------------------------------------------------------------------- 1 | \documentclass{standalone} 2 | \usepackage{tikz}\usetikzlibrary{calc} 3 | \begin{document} 4 | \begin{tikzpicture}[ 5 | every node/.style={ 6 | draw, circle, line width=3pt, 7 | outer sep=0pt, inner sep=1pt, 8 | }, 9 | ] 10 | 11 | \def\drawNodes{ 12 | \node (A) at (0,-\n*.25) {}; 13 | \node (B) at (1,-\n*.25) {}; 14 | } 15 | 16 | \def\n{0}\drawNodes 17 | \path [yellow] (A) edge (B); 18 | 19 | \def\n{1}\drawNodes 20 | \path [red] (A) edge [shorten >=1.5pt] (B); 21 | 22 | \def\n{2}\drawNodes 23 | \path [cyan] (A) edge [shorten <=1.5pt] (B); 24 | 25 | \def\n{3}\drawNodes 26 | \path [green] (A) edge [->] ($(A)!.5!(B)$) edge (B); 27 | 28 | \def\n{4}\drawNodes 29 | \path [magenta] (A) edge [->] ($(A)!.5!(B)$) edge [shorten >=1.5pt] (B); 30 | 31 | \def\n{5}\drawNodes 32 | \path (A) edge [->, shorten <=1.5pt, orange] ($(A)!.5!(B)$) ($(A)!.5!(B)$) edge [shorten >=1.5pt, purple] (B); 33 | 34 | \def\n{6}\drawNodes 35 | \path [brown, shorten <=1.5pt] (A) edge [shorten >=1.5pt] (B) edge [->, blue] ($(A)!.5!(B)$); 36 | 37 | \end{tikzpicture} 38 | \end{document} -------------------------------------------------------------------------------- /alignment_issue.tex: -------------------------------------------------------------------------------- 1 | \documentclass{standalone} 2 | \usepackage{tikz} 3 | \usetikzlibrary{graphs,positioning} 4 | \begin{document} 5 | \begin{tikzpicture}[scale=0.75, 6 | every node/.style = { 7 | circle, 8 | very thick, 9 | inner sep = 0, 10 | outer sep = 0, 11 | minimum size = 0.75cm, 12 | draw = black, 13 | scale = 1, 14 | }, 15 | ] 16 | \graph[grow right sep = 5mm]{ 17 | 1 -> 2 -> 3 -> 4 18 | }; 19 | \draw[help lines] (-0.5, -1.5) grid (8, 1.5); 20 | \end{tikzpicture} 21 | \end{document} 22 | 23 | % I would like the following 10mm nodes to be fitting a 10mm grid using the `graph` command. Instead, the thickness is adding up (I would like TikZ to ignore it). 24 | 25 | % [![misaligned nodes][1]][1] 26 | 27 | % \documentclass{standalone} 28 | % \usepackage{tikz} 29 | % \usetikzlibrary{graphs,positioning} 30 | % \begin{document} 31 | % \begin{tikzpicture}[ 32 | % every node/.style = { 33 | % circle, 34 | % very thick, 35 | % inner sep = 0, 36 | % minimum size = 10mm, 37 | % draw = black, 38 | % }, 39 | % ] 40 | % \graph[grow right sep=10mm]{ 41 | % 1 -> 2 -> 3 -> 4 42 | % }; 43 | % \draw[help lines] (-0.5,-1.5) grid (8,1.5); 44 | % \end{tikzpicture} 45 | % \end{document} 46 | 47 | % Am I supposed to size my nodes 10mm − "very thick"??? Sounds a little insane. 48 | 49 | 50 | % [1]: https://i.imgur.com/xLLP1ZZ.png -------------------------------------------------------------------------------- /coolwarm-colormap.tex: -------------------------------------------------------------------------------- 1 | \documentclass[border=5mm]{minimal} 2 | \usepackage{pgfplots}\pgfplotsset{compat=newest} 3 | 4 | % Colourmap visualiser 5 | \def\pgfplotsshowcolormap#1{% 6 | \pgfplotscolormapifdefined{#1}{\relax}{% 7 | \pgfplotsset{colormap/#1}% 8 | }% 9 | \pgfplotscolormaptoshadingspec{#1}{8cm}\result 10 | \def\tempb{\pgfdeclarehorizontalshading{tempshading}{1cm}}% 11 | \expandafter\tempb\expandafter{\result}% 12 | \pgfuseshading{tempshading}% 13 | } 14 | 15 | \pgfkeys{% 16 | /pgfplots/colormap/coolwarm/.style={% 17 | /pgfplots/colormap={coolwarm}{% 18 | rgb=(0.2298057 , 0.29871797, 0.75368315) 19 | rgb=(0.29944126, 0.40024818, 0.83984198) 20 | rgb=(0.37355243, 0.49749871, 0.90946737) 21 | rgb=(0.45173856, 0.58818099, 0.96020127) 22 | rgb=(0.53256824, 0.6698006 , 0.99039327) 23 | rgb=(0.61393265, 0.73992298, 0.99914237) 24 | rgb=(0.69332128, 0.79631413, 0.98630778) 25 | rgb=(0.76803436, 0.83703522, 0.95248822) 26 | rgb=(0.83534471, 0.860514 , 0.89897041) 27 | rgb=(0.89588177, 0.84990606, 0.82349908) 28 | rgb=(0.94087894, 0.8055964 , 0.73516656) 29 | rgb=(0.96483536, 0.74461367, 0.64323888) 30 | rgb=(0.96810534, 0.6684752 , 0.55048622) 31 | rgb=(0.95125379, 0.57879939, 0.45940781) 32 | rgb=(0.91515712, 0.47692653, 0.37217941) 33 | rgb=(0.8610536 , 0.36291576, 0.29062813) 34 | rgb=(0.79056153, 0.231397 , 0.21624204) 35 | rgb=(0.70567316, 0.01555616, 0.15023281) 36 | }% 37 | }, 38 | } 39 | 40 | \begin{document} 41 | \strut{}Colormap \texttt{viridis}. 42 | 43 | % \pgfplotsset{colormap name=viridis} 44 | \pgfplotsshowcolormap{viridis} 45 | 46 | \strut{}Colormap \texttt{coolwarm}. 47 | 48 | % \pgfplotsset{colormap name=coolwarm} 49 | \pgfplotsshowcolormap{coolwarm} 50 | \end{document} -------------------------------------------------------------------------------- /grid.tex: -------------------------------------------------------------------------------- 1 | \documentclass{standalone} 2 | %\url{} 3 | \usepackage{tikz} 4 | 5 | \makeatletter 6 | \def\grd@save@target#1{% 7 | \def\grd@target{#1}} 8 | \def\grd@save@start#1{% 9 | \def\grd@start{#1}} 10 | \tikzset{ 11 | grid with coordinates/.style={ 12 | to path={% 13 | \pgfextra{% 14 | \edef\grd@@target{(\tikztotarget)}% 15 | \tikz@scan@one@point\grd@save@target\grd@@target\relax 16 | \edef\grd@@start{(\tikztostart)}% 17 | \tikz@scan@one@point\grd@save@start\grd@@start\relax 18 | \draw[minor help lines] (\tikztostart) grid (\tikztotarget); 19 | \draw[major help lines] (\tikztostart) grid (\tikztotarget); 20 | \grd@start 21 | \pgfmathsetmacro{\grd@xa}{\the\pgf@x/1cm} 22 | \pgfmathsetmacro{\grd@ya}{\the\pgf@y/1cm} 23 | \grd@target 24 | \pgfmathsetmacro{\grd@xb}{\the\pgf@x/1cm} 25 | \pgfmathsetmacro{\grd@yb}{\the\pgf@y/1cm} 26 | \pgfmathsetmacro{\grd@xc}{\grd@xa + \pgfkeysvalueof{/tikz/grid with coordinates/major step}} 27 | \pgfmathsetmacro{\grd@yc}{\grd@ya + \pgfkeysvalueof{/tikz/grid with coordinates/major step}} 28 | \foreach \x in {\grd@xa,\grd@xc,...,\grd@xb} 29 | \node[anchor=north] at (\x,\grd@ya) {\pgfmathprintnumber{\x}}; 30 | \foreach \y in {\grd@ya,\grd@yc,...,\grd@yb} 31 | \node[anchor=east] at (\grd@xa,\y) {\pgfmathprintnumber{\y}}; 32 | } 33 | } 34 | }, 35 | minor help lines/.style={ 36 | help lines, 37 | step=\pgfkeysvalueof{/tikz/grid with coordinates/minor step} 38 | }, 39 | major help lines/.style={ 40 | help lines, 41 | line width=\pgfkeysvalueof{/tikz/grid with coordinates/major line width}, 42 | step=\pgfkeysvalueof{/tikz/grid with coordinates/major step} 43 | }, 44 | grid with coordinates/.cd, 45 | minor step/.initial=.25, 46 | major step/.initial=1, 47 | major line width/.initial=0.5pt, 48 | } 49 | \makeatother 50 | \begin{document} 51 | \begin{tikzpicture} 52 | \draw[help lines,step=.2] (-2,-2) grid (7,4); 53 | \draw[help lines,line width=.6pt,step=1] (-2,-2) grid (7,4); 54 | \foreach \x in {-2,-1,0,1,2,3,4,5,6,7} 55 | \node[anchor=north] at (\x,-2) {\x}; 56 | \foreach \y in {-2,-1,0,1,2,3,4} 57 | \node[anchor=east] at (-2,\y) {\y}; 58 | \end{tikzpicture} 59 | 60 | \begin{tikzpicture} 61 | \draw (-2,-2) to[grid with coordinates, scale=0.75] (7,4); 62 | \end{tikzpicture} 63 | \end{document} -------------------------------------------------------------------------------- /annotated-equations.tex: -------------------------------------------------------------------------------- 1 | \documentclass{minimal} 2 | \usepackage{mathtools} 3 | \usepackage{tikz} 4 | \usetikzlibrary{tikzmark,calc,fit} 5 | 6 | \begin{document} 7 | 8 | \begin{equation*} 9 | y=\tikzmark{mark1}m\tikzmark{mark2} \cdot x + \tikzmark{mark3}q\tikzmark{mark4} 10 | \end{equation*} 11 | \vspace{1cm} 12 | \begin{tikzpicture}[overlay,remember picture] 13 | 14 | \node [fit=(pic cs:mark1)(pic cs:mark2),inner sep=2pt,minimum height=3ex,yshift=0.5ex,blue!20,draw,thick,rounded corners] (a) {}; 15 | \node [fit=(pic cs:mark3)(pic cs:mark4),inner sep=2pt,minimum height=3ex,yshift=0.5ex,red!20,draw,thick,rounded corners] (b) {}; 16 | 17 | \draw [->] (a) to[bend left] ++(2,1) node[right] {angular coefficient}; 18 | \draw [->] (b) to[bend right] ++(1,-1) node[right] {$y$-intercept}; 19 | \end{tikzpicture} 20 | \begin{equation*} 21 | y=\tikzmark{mark1}m\tikzmark{mark2} \cdot x + \tikzmark{mark3}q\tikzmark{mark4} 22 | \end{equation*} 23 | 24 | \usetikzlibrary{positioning} 25 | 26 | \vspace{2cm} 27 | 28 | \begin{equation*} 29 | y = \tikz[baseline=(n1.base)]{\node[fill=yellow!50, draw, circle, inner sep=1.5pt] (n1){$m$}; 30 | \node[overlay, above right=of n1] (t1) {angular coefficient}; 31 | \draw [overlay, ->] (n1.north) to [bend left=45] (t1.west); 32 | } 33 | % \hspace{-1cm} 34 | \cdot x +\tikz[baseline=(n2.base)]{\node[fill=green!50, draw, circle, anchor=south, inner sep=1.5pt] (n2){$q$}; 35 | \node[overlay, below right=of n2] (t2) {$y$-intercept}; 36 | \draw [overlay, ->] (n2.south) to [bend right=45] (t2.west); 37 | } 38 | \end{equation*} 39 | 40 | \vspace{2cm} 41 | 42 | \begin{equation*} 43 | y = 44 | \tikz[baseline=(a.base)]{ 45 | \node[circle, draw=blue, fill=blue!60, inner sep=1pt] (a) {$a$}; 46 | \draw[overlay, blue, thick, ->] (a.north) to[out=90, in=180] +(30:1cm) 47 | node[anchor=west,text=black] {angular coefficient}; 48 | } 49 | \cdot x + 50 | \tikz[baseline=(q.base)]{ 51 | \node[circle, draw=green, fill=green!60, inner sep=1pt] (q) {$q$}; 52 | \draw[overlay, green, thick, ->] (a.south) to[out=-90, in=180] +(-30:1cm) 53 | node[anchor=west,text=black] {y-intercept}; 54 | } 55 | \end{equation*} 56 | \vspace{1cm} 57 | 58 | Drawing a red node 59 | \tikz[remember picture]{\node [circle, fill=red!50] (n1) {};} 60 | and a blue one 61 | \tikz[remember picture]{\node [circle, fill=blue!50] (n2) {};}. 62 | Now, I'm drawing a curved arrow between them. 63 | \tikz[remember picture, overlay]{\draw[->, bend left=45] (n1) to (n2);} 64 | 65 | % \begin{tikzpicture}[remember picture, overlay, out=45,in=135] 66 | % \draw (n1) to (n2) 67 | % (0,0) to (2,0) 68 | % (0,0) to (3,0); 69 | % \end{tikzpicture} 70 | 71 | \end{document} -------------------------------------------------------------------------------- /tut-5.tex: -------------------------------------------------------------------------------- 1 | \section*{Tutorial 5} 2 | 3 | \noindent 4 | \begin{tikzpicture}[ 5 | node distance=5mm, 6 | text height=1.4ex,text depth=.25ex, 7 | ] 8 | % \node[nonterminal] {unsigned integer}; 9 | \node (ui1) [nonterminal] {unsigned integer}; 10 | \node (dot) [terminal,right=of ui1] {.}; 11 | \node (digit) [terminal,right=of dot] {digit}; 12 | \node (E) [terminal,right=of digit] {E}; 13 | \node (plus) [terminal,above right=of E,xshift=5mm] {+}; 14 | \node (minum) [terminal,below right=of E,xshift=5mm] {-}; 15 | \node (ui2) [nonterminal,below right=of plus,xshift=5mm] {unsigned integer}; 16 | \end{tikzpicture} 17 | 18 | \noindent 19 | \begin{tikzpicture}[ 20 | point/.style={circle,inner sep=0pt,minimum size=2pt,fill=red}, 21 | % text height=1.4ex,text depth=.25ex, 22 | ] 23 | \matrix[row sep=1mm,column sep=2mm]{ 24 | % First row 25 | &&&&&&&&&&& \node (plus) [terminal] {+}; \\ 26 | % Second row 27 | \node (p1) [point] {}; & \node (ui1) [nonterminal] {unsigned integer}; & 28 | \node (p2) [point] {}; & \node (dot) [terminal] {.}; & 29 | \node (p3) [point] {}; & \node (digit) [terminal] {digit}; & 30 | \node (p4) [point] {}; & \node (p1) [point] {}; & 31 | \node (p6) [point] {}; & \node (E) [terminal] {E}; & 32 | \node (p7) [point] {}; & & 33 | \node (p8) [point] {}; & \node (ui2) [nonterminal] {unsigned integer}; & 34 | \node (p9) [point] {}; & \node (p10) [point] {}; \\ 35 | % Third row 36 | &&&&&&&&&&& \node (minus) [terminal] {-}; \\ 37 | }; 38 | \end{tikzpicture} 39 | 40 | \noindent 41 | \usetikzlibrary{graphs} 42 | \begin{tikzpicture}[ 43 | point/.style={circle,inner sep=0pt,minimum size=2pt,fill=red}, 44 | % text height=1.4ex,text depth=.25ex, 45 | skip loop/.style={to path={-- ++(0,#1) -| (\tikztotarget))}}, 46 | ] 47 | \matrix[row sep=1mm,column sep=2mm]{ 48 | % First row 49 | &&&&&&&&&&& \node (plus) [terminal] {+}; \\ 50 | % Second row 51 | \node (p1) [point] {}; & \node (ui1) [nonterminal] {unsigned integer}; & 52 | \node (p2) [point] {}; & \node (dot) [terminal] {.}; & 53 | \node (p3) [point] {}; & \node (digit) [terminal] {digit}; & 54 | \node (p4) [point] {}; & \node (p5) [point] {}; & 55 | \node (p6) [point] {}; & \node (E) [terminal] {E}; & 56 | \node (p7) [point] {}; & & 57 | \node (p8) [point] {}; & \node (ui2) [nonterminal] {unsigned integer}; & 58 | \node (p9) [point] {}; & \node (p10) [point] {}; \\ 59 | % Third row 60 | &&&&&&&&&&& \node (minus) [terminal] {-}; \\ 61 | }; 62 | \graph{ 63 | (p1) -> (ui1) -- (p2) -> (dot) -- (p3) -> (digit) -- (p4) -- (p5) -- (p6) 64 | -> (E) -- (p7) -- (p8) -> (ui2) -- (p9) -> (p10); 65 | (p4) -> [skip loop=-5mm] (p3); 66 | }; 67 | \end{tikzpicture} -------------------------------------------------------------------------------- /tut-3.tex: -------------------------------------------------------------------------------- 1 | \section*{Tutorial 3} 2 | 3 | \noindent 4 | \begin{tikzpicture} 5 | \path ( 0,2) node [shape=circle,draw] {} 6 | ( 0,1) node [shape=circle,draw] {} 7 | ( 0,0) node [shape=circle,draw] {} 8 | ( 1,1) node [shape=rectangle,draw] {} 9 | (-1,1) node [shape=rectangle,draw] {}; 10 | \end{tikzpicture} 11 | 12 | \noindent 13 | \begin{tikzpicture} 14 | \node at ( 0,2) [circle,draw] {}; 15 | \node at ( 0,1) [circle,draw] {}; 16 | \node at ( 0,0) [circle,draw] {}; 17 | \node at ( 1,1) [rectangle,draw] {}; 18 | \node at (-1,1) [rectangle,draw] {}; 19 | \end{tikzpicture} 20 | 21 | \noindent 22 | \begin{tikzpicture} 23 | \node at ( 0,2) [circle,draw=blue!50,fill=blue!20] {}; 24 | \node at ( 0,1) [circle,draw=blue!50,fill=blue!20] {}; 25 | \node at ( 0,0) [circle,draw=blue!50,fill=blue!20] {}; 26 | \node at ( 1,1) [rectangle,draw=black!50,fill=black!20] {}; 27 | \node at (-1,1) [rectangle,draw=black!50,fill=black!20] {}; 28 | \end{tikzpicture} 29 | 30 | \noindent 31 | \begin{tikzpicture} 32 | [ 33 | place/.style={circle,draw=blue!50,fill=blue!20}, 34 | transition/.style={rectangle,draw=black!50,fill=black!20}, 35 | ] 36 | \node at ( 0,2) [place] {}; 37 | \node at ( 0,1) [place] {}; 38 | \node at ( 0,0) [place] {}; 39 | \node at ( 1,1) [transition] {}; 40 | \node at (-1,1) [transition] {}; 41 | \end{tikzpicture} 42 | 43 | \noindent 44 | \begin{tikzpicture} 45 | [ 46 | inner sep=0mm, 47 | place/.style={circle,draw=blue!50,fill=blue!20,minimum size=6mm}, 48 | transition/.style={rectangle,draw=black!50,fill=black!20,minimum size=4mm}, 49 | ] 50 | \node at ( 0,2) [place] {}; 51 | \node at ( 0,1) [place] {}; 52 | \node at ( 0,0) [place] {}; 53 | \node at ( 1,1) [transition] {}; 54 | \node at (-1,1) [transition] {}; 55 | \end{tikzpicture} 56 | 57 | \noindent 58 | \begin{tikzpicture} 59 | [ 60 | inner sep=0mm, 61 | place/.style={circle,draw=blue!50,fill=blue!20,minimum size=6mm}, 62 | transition/.style={rectangle,draw=black!50,fill=black!20,minimum size=4mm}, 63 | ] 64 | \node[place] (waiting) at ( 0,2) {}; 65 | \node[place] (critical) at ( 0,1) {}; 66 | \node[place] (semaphore) at ( 0,0) {}; 67 | \node[transition] (leave critical) at ( 1,1) {}; 68 | \node[transition] (enter critical) at (-1,1) {}; 69 | \end{tikzpicture} 70 | 71 | \noindent 72 | \usetikzlibrary{positioning} 73 | \begin{tikzpicture} 74 | [ 75 | inner sep=0mm, 76 | place/.style={circle,draw=blue!50,fill=blue!20,minimum size=6mm}, 77 | transition/.style={rectangle,draw=black!50,fill=black!20,minimum size=4mm}, 78 | ] 79 | \node[place] (waiting) {}; 80 | \node[place] (critical) [below=of waiting] {}; 81 | \node[place] (semaphore) [below=of critical] {}; 82 | \node[transition] (leave critical) [right=of critical] {}; 83 | \node[transition] (enter critical) [left=of critical] {}; 84 | \end{tikzpicture} 85 | 86 | \noindent 87 | \usetikzlibrary{positioning} 88 | \begin{tikzpicture} 89 | [ 90 | inner sep=0mm, 91 | place/.style={circle,draw=blue!50,fill=blue!20,minimum size=6mm}, 92 | transition/.style={rectangle,draw=black!50,fill=black!20,minimum size=4mm}, 93 | ] 94 | % Nodes placement 95 | \node[place] (waiting) {}; 96 | \node[place] (critical) [below=of waiting] {}; 97 | \node[place] (semaphore) [below=of critical] {}; 98 | \node[transition] (leave critical) [right=of critical] {}; 99 | \node[transition] (enter critical) [left=of critical] {}; 100 | % Connectors 101 | \draw[->] (enter critical) to (critical); 102 | %\draw[->] (waiting) to [out=180,in=90] (enter critical); 103 | %\draw[->] (waiting) to (enter critical); 104 | \draw[->] (waiting) to [bend right=45] (enter critical); 105 | \end{tikzpicture} 106 | 107 | \noindent 108 | \usetikzlibrary{positioning} 109 | \begin{tikzpicture} 110 | [ 111 | inner sep=0mm, 112 | place/.style={circle,draw=blue!50,fill=blue!20,minimum size=6mm}, 113 | transition/.style={rectangle,draw=black!50,fill=black!20,minimum size=4mm}, 114 | ] 115 | % Nodes placement 116 | \node[place] (waiting) {}; 117 | \node[place] (critical) [below=of waiting] {}; 118 | \node[place] (semaphore) [below=of critical] {}; 119 | \node[transition] (leave critical) [right=of critical] {}; 120 | \node[transition] (enter critical) [left=of critical] {} 121 | edge[->] (critical) 122 | edge[<-,bend left=45] (waiting) 123 | edge[->,bend right=45] (semaphore); 124 | \end{tikzpicture} 125 | 126 | \noindent 127 | \usetikzlibrary{positioning} 128 | \begin{tikzpicture} 129 | [ 130 | inner sep=0mm, 131 | place/.style={circle,draw=blue!50,fill=blue!20,minimum size=6mm}, 132 | transition/.style={rectangle,draw=black!50,fill=black!20,minimum size=4mm}, 133 | bend angle=45, 134 | ] 135 | 136 | % Nodes placement 137 | \node[place] (waiting) {}; 138 | \node[place] (critical) [below=of waiting] {}; 139 | \node[place] (semaphore) [below=of critical] {}; 140 | 141 | % Nodes with edges 142 | \node[transition] (leave critical) [right=of critical] {} 143 | edge[<-] (critical) 144 | edge[->, bend right] (waiting) 145 | edge[<-, bend left] (semaphore); 146 | \node[transition] (enter critical) [left=of critical] {} 147 | edge[->] (critical) 148 | edge[<-,bend left] (waiting) 149 | edge[->,bend right] (semaphore); 150 | \end{tikzpicture} --------------------------------------------------------------------------------