Membuat Gambar di LaTeX dengan TikZ
Selain untuk membuat artikel, soal ujian, buku, presentasi, di LaTex juga kita bisa membuat gambar berupa diagram dan bentuk gambar lainnya dengan mudah, sebagai contoh membuat gambar atau diagram flowchart.
Untuk memulai TikZ kita perlu memanggil tikz package yaitu
\usepackage{tikz}
kemudian tuliskan kode di antara \begin .. dan \end
\begin{tikzpicture}
<masukkan kode disini>
\end{tikzpicture}
Berikut contoh perintah membuat gambar di LaTeX dengan TikZ:
\draw (0,0) -- (4,0);
\draw (0,0) -- (4,0) -- (4,4) -- (0,4) -- (0,0);
\draw (0,0) -- (4,0) -- (4,4) -- (0,4) -- cycle;
\draw (0.0) rectangle (4,4);
\draw (0,0) parabola (4,4);
\draw (0,0) .. controls (0,4) and (4,0) .. (4,4);
\draw (2,2) circle (3cm);
\draw (2,2) ellipse (3cm and 1cm);
\draw (3,0) arc (0:75: 3cm);
\draw[red,thick,dashed] (2,2) circle (3cm);
\draw[step=1cm,gray,very thin] (-2,-2) grid (6,6);
\draw[step=1cm,gray,very thin] (-1.9,-1.9) grid (5.9,5.9);
\fill[blue!40!white] (0,0) rectangle (4,4);
\filldraw[fill=blue!40!white, draw=black] (0,0) rectangle (4,4);
\draw[thick,->] (0,0) -- (4.5,0);
\draw[thick,->] (0,0) -- (0,4.5);
\draw[thick,->] (0,0) -- (4.5,0) node[anchor=north west] {x axis};
\draw[thick,->] (0,0) -- (0,4.5) node[anchor=south east] {y axis};
\foreach \x in {0,1,2,3,4}
\draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north] {$\x$};
\foreach \y in {0,1,2,3,4}
\draw (1pt,\y cm) -- (-1pt,\y cm) node[anchor=east] {$\y$};
Contoh: Membuat Diagram Flowchart di LateX
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=orange!30]
\tikzstyle{decision} = [diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
Nodes
\begin{tikzpicture}[node distance=2cm]
<tikz code>
\end{tikzpicture}
\node (start) [startstop] {Start};
\node (in1) [io, below of=start] {Input};
\node (pro1) [process, below of=in1] {Process 1};
\node (dec1) [decision, below of=pro1] {Decision 1};
\node (dec1) [decision, below of=pro1, yshift=-0.5cm] {Decision 1};
\node (pro2a) [process, below of=dec1, yshift=-0.5cm] {Process 2a};
\node (pro2b) [process, right of=dec1, xshift=2cm] {Process 2b};
\node (out1) [io, below of=pro2a] {Output};
\node (stop) [startstop, below of=out1] {Stop};
Arrows
\draw [arrow] (start) -- (in1);
\draw [arrow] (in1) -- (pro1);
\draw [arrow] (pro1) -- (dec1);
\draw [arrow] (dec1) -- (pro2a);
\draw [arrow] (dec1) -- (pro2b);
\draw [arrow] (dec1) -- node {yes} (pro2a);
\draw [arrow] (dec1) -- node {no} (pro2b);
\draw [arrow] (dec1) -- node[anchor=east] {yes} (pro2a);
\draw [arrow] (dec1) -- node[anchor=south] {no} (pro2b);
\draw [arrow] (pro2b) -- (pro1);
\draw [arrow] (pro2a) -- (out1);
\draw [arrow] (out1) -- (stop);
\draw [arrow] (pro2b) |- (pro1);
Text Width
\node (pro2a) [process, below of=dec1, yshift=-0.5cm] {Process 2a text text text text text text text text text text};
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, text width=3cm, draw=black, fill=orange!30]
Lebih banyak contoh di awesomeopensource.com