Equations
Drawing 2D graph Drawing 3D graph
Drawing geometry figures
Page 1 Page 2
Matrix Fractal Tree Writing notes Symbols Induction Basics Equations system Math environment Accents Venn diagrams
Drawin figures in LaTeX 2.

Drawing in Latex using the TikZ package can sometimes be hard and time consuming, but the result is guaranteed to be excellent and of high quality. So in this section we will take a deeper look at how to draw figures with TikZ. This can be really useful to display geometry figures for exercises or examples.
Don't forget to add the package before the main document.

CODE
\usepackage{tikz}

Drawing grids.
With Latex we can also draw grids as a background for our figures, to draw a grid we need to set the parameters inside the [option] parentesis. With [step= x cm] we will set how large each square will be, then we can choose the color and the thickness by simply adding them after the "step", here is an example:

CODE
\begin{tikzpicture}
\draw[step=1cm,black,very thin] (0,0) grid (5,5);
\end{tikzpicture}



Filling figures.
It is possible to draw figures filled with a color, for example a red square or a blue sphere, it's very simple: instead of starting our figure with "\draw", we start with "fill" and we put the color inside the [option] parentesis.

CODE
\begin{tikzpicture}
\draw[step=1cm,black,very thin] (0,0) grid (5,5);
\fill[blue] (1,1) rectangle (2,2);
\fill[red] (2,3) rectangle (4,4);
\end{tikzpicture}



Adding text
If we want to display some text on a figure we can draw a node on a specific coordinate and adding text to it. The code is quite simple: \draw (coordinate x,coordinate y) node{text};
Here is an example where we add on top of a square its color:
CODE
\begin{tikzpicture}
\draw[step=1cm,black,very thin] (0,0) grid (5,5);
\fill[blue] (0,1) rectangle (1,2);
\draw (0.5,2.5) node{blue};
\fill[red] (2,3) rectangle (3,4);
\draw (2.5,4.5) node{red};
\fill[green](3,0) rectangle (4,1);
\draw (3.5,1.5) node{green};
\end{tikzpicture}



Drawing arrows.
In Latex we aren't limited just to straight line, we can also draw arrows, this can be very useful if we want to represent vector, drawing graph or point something. To draw an arrow we just need to add inside the [option] the simbol: ->
The general formula is: \draw[->] (x1,y1) -- (x2,y2);
CODE
\begin{tikzpicture}
\draw (1,1) circle (1cm);
\draw[thick,->] (2,2) -- (1,1);
\draw(2.5,2.2) node{center};
\end{tikzpicture}



Putting everything together.
With patience and some effort we can have great result, here are some more example to show just a fraction of the possibility of LaTeX:
CODE
\begin{tikzpicture}
\draw[step=1cm,black,very thin] (0,0) grid (8,5);
\draw[thick,->](0,0) -- (8,0);
\draw[thick,->](0,0) -- (0,5);
\draw(8.5,0) node{time};
\draw(0,5.4) node{cost};
\draw[->] (0,0) -- (2,1) -- (3,3) -- (4,2) -- (5,1.5) -- (7,2) -- (8,2.5);
\draw(3,3.3) node{max};
\end{tikzpicture}





CODE
\begin{tikzpicture}
\fill[black](0,8) -- (1,8) -- (1,7.9) -- (0,7.9) --cycle;
\fill[black](0,6.6) -- (1,6.6) parabola (1.5,6.8) -- (1.6,6.8) -- (1.5,6.5) -- (0,6.5);
\fill[black](0.3,8) -- (0.5,8) -- (0.5,6.5) -- (0.3,6.5);
\fill[black](1,6.7) -- (1.7,8) -- (1.8,8) -- (2.5,6.7) -- (2.3,6.7) -- (1.7,7.8) -- (1.1,6.7);
\fill[black](1.3,7.1) -- (2.2,7.1) -- (2.1,7) --(1.2,7);
\fill[black](2,8) -- (3.5,8) -- (3.5,7.9) -- (2,7.9);
\fill[black](2.7,8) -- (2.9,8) -- (2.9,6.5) -- (2.7,6.5);
\fill[black](2.3,6.6) -- (3.2,6.6) -- (3.2,6.5) -- (2.3,6.5);
\fill[black](3.3,7.5) -- (3.3,6) -- (3.5,6) -- (3.5,7.5);
\fill[black](3.1,7.5) -- (4.2,7.5) -- (4.2,7.4) -- (3.1,7.4);
\fill[black](3.1,6) -- (4.2,6) -- (4.2,6.1) -- (3.1,6.1);
\fill[black](3.3,6.8) -- (4,6.8) -- (4,6.7) -- (3.3,6.7);
\fill[black](3.9,7) -- (4,7) -- (4,6.5) -- (3.9,6.5);
\fill[black](4.2,6) -- (4.3,6) -- (4.3,6.3) -- (4.2,6.3);
\fill[black](4.2,7.5) -- (4.3,7.5) -- (4.3,7.2) -- (4.2,7.2);
\fill[black](4.3,6.3) -- (4.4,6.3) -- (5.6,8) -- (5.5,8);
\fill[black](4.3,8) -- (4.5,8) -- (5.7,6.3) -- (5.5,6.3);
\fill[black](4.1,6.3) -- (4.6,6.3) -- (4.6,6.4) -- (4.1,6.4);
\fill[black](4.1,8) -- (4.6,8) -- (4.6,7.9) -- (4.1,7.9);
\fill[black](5.4,6.3) -- (5.9,6.3) -- (5.9,6.4) -- (5.4,6.4);
\fill[black](5.4,8) -- (5.9,8) -- (5.9,7.9) -- (5.4,7.9);
\end{tikzpicture}


Exercise.

Now try to reproduce this cilinder:

For the solution move te mouse over the black box on the right.

\begin{tikzpicture}
\draw(0,0) ellipse (2cm and 0.8cm);
\draw(-2,0) -- (-2,3);
\draw(2,0) -- (2,3);
\draw(0,3) ellipse (2cm and 0.8cm);
\draw(0,3) -- (2,3);
\draw(1,3.2) node{x};
\draw(2.2,1.5) node{h};
\end{tikzpicture}