Graphs
You can do vector graphics
by using:
\usepackage{tikz}
\begin{tikzpicture}
\end{tikzpicture}
to draw something, we use \draw
command (or \filldraw
):
\draw[OPTIONS] (START_COORDS) SHAPE (END_COORDS);
The OPTIONS
include:
- color
- style
- thickness
Colors
- white
- black
- red
- green
- blue
- cyan
- magenta
- yellow
Thickness
- ultra thin
- very thin
- thin
- thick
- very thick
- ultra thick
Nodes
The capitalized words in the following code block are placeholders which I will describe afterwards.
% preamble
\usetikzlibrary{positioning}
% doc starts
\begin{tikzpicture}[
NODE_TYPE/.style={SHAPE, draw=COLOR!INTENSITY, fill=COLOR!INTENSITY, THICKNESS, minimum size=WIDTH},
]
\node[NODE_TYPE] (NODE_NAME_1) {NODE_LABEL};
\node[NODE_TYPE] (NODE_NAME_2) [below = of NODE_NAME_1]{NODE_LABEL};
\draw[->] (NODE_NAME.DIRECTION) -- (NODE_NAME.DIRECTION);
\end{tikzpicture}
Let me explain those placeholders now.
NODE_TYPE
is assigned to each node, to identify its type (appearance).SHAPE
can becircle
,rectangle
etc.DIRECTION
can be:east
west
north
south
north east
north west
south east
south west
--
defines aline
.->
tells the line has to be pointed.
Examples
\draw[red, dashed] (0, 0) rectangle (2, -2) node[anchor=north west, blue] {Hello};
\draw[red, dashed, ultra thick] (0, 0) circle (2);
\begin{tikzpicture}[
roundnode/.style={circle, draw=green!60, fill=green!5, very thick, minimum size=7mm},
squarednode/.style={rectangle, draw=red!60, fill=red!5, very thick, minimum size=5mm},
]
%Nodes
\node[squarednode] (maintopic) {2};
\node[roundnode] (uppercircle) [above=of maintopic] {1};
\node[squarednode] (rightsquare) [right=of maintopic] {3};
\node[roundnode] (lowercircle) [below=of maintopic] {4};
%Lines
\draw[->] (uppercircle.south) -- (maintopic.north);
\draw[->] (maintopic.east) -- (rightsquare.west);
\draw[->] (rightsquare.south) .. controls +(down:7mm) and +(right:7mm) .. (lowercircle.east);
\end{tikzpicture}