tikz

Table of Contents

1. tutorials

2. latex setting

you need to use the tikz package, and write all your tikz code in the environment tikzpicture

\usepackage{tikz}
% ..
\begin{tikzpicture}
\end{tikzpicture}
\usepackage{tikz}
% ..
\begin{tikzpicture}
\end{tikzpicture}

3. org-mode setting

According to https://fanpengkong.com/post/org-graphics/, you need the following for latex source blocks babel to work with tikz

(setq org-latex-create-formula-image-program 'imagemagick)
(setq org-latex-packages-alist
      (quote (("" "color" t)
          ("" "minted" t)
          ("" "parskip" t)
          ("" "tikz" t))))

4. \draw

draw lines with a standard x,y coordinate system:

0,2    
0,1    
0,0 1,0 2,0

tikz_draw.png

5. \draw a cycle

tikz_cycle.png

6. \draw a shape

6.1. rectangle

\begin{tikzpicture}
\draw (0,0) rectangle (4,4);
\end{tikzpicture}

tikz_shape_rectangle.png

6.2. parabola

\begin{tikzpicture}
\draw (0,0) parabola (4,4);
\end{tikzpicture}

tikz_shape_parabola.png

6.3. circle

\begin{tikzpicture}
\draw (0,0) circle (2);
\end{tikzpicture}

tikz_shape_circle.png

6.4. ellipse

\begin{tikzpicture}
\draw (0,0) ellipse (2 and 3); % x-direction radius and y-direction radious
\end{tikzpicture}

tikz_shape_ellipse.png

6.5. arc

\begin{tikzpicture}
\draw (0,0) arc (-20:75:3); % start angle, end angle, radius
\end{tikzpicture}

tikz_shape_arc.png

6.6. customize shape

\begin{tikzpicture}
\draw[red,thick,dashed] (2,2) circle (3cm);
\end{tikzpicture}

tikz_customize.png

6.7. grid

\begin{tikzpicture}
\draw[step=1cm,gray,very thin] (-2,-2) grid (6,6);
\draw[red,thick,dashed] (2,2) circle (3cm);
\end{tikzpicture}

tikz_grid.png

\begin{tikzpicture}
\draw[step=1cm,gray,very thin] (-1.9,-1.9) grid (5.9,5.9);
\draw[red,thick,dashed] (2,2) circle (3cm);
\end{tikzpicture}

tikz_grid.png

7. \draw with control point

\begin{tikzpicture}
\draw (0,0) .. controls (0,4) and (4,0) .. (4,4);
\end{tikzpicture}

tikz_curve.png

8. \fill, \filldraw, \shade, \shadedraw

\begin{tikzpicture}
\fill[blue!40!white] (0,0) rectangle (4,4);
\end{tikzpicture}

fill_plain.png

\begin{tikzpicture}
\fill[blue!40!white, draw=green] (0,0) rectangle (4,4);
\end{tikzpicture}

filldraw_plain.png

\begin{tikzpicture}
\shade[left color= red, right color= blue] (0,0) rectangle (4,4);
\end{tikzpicture}

shade_plain.png the shade pairs:

  • left and right
  • top and bottom
  • inner and outer
\begin{tikzpicture}
\shadedraw[inner color= red, outer color= blue, draw=green] (0,0) rectangle (4,4);
\end{tikzpicture}

9. \draw an axe

\begin{tikzpicture}
\draw[step=1cm,gray,very thin] (-2,-2) grid (6,6);
\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};
\end{tikzpicture}

tikz_axe.png

  • node = a keyword for a point in tikz, property in [], and text in {}
\begin{tikzpicture}
\draw[step=1cm,gray,very thin] (-2,-2) grid (6,6);
\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$};
\end{tikzpicture}

tikz_axe_foreach.png

10. export tikz from geogebra

geogebra provides an export to tikz functionality

Backlinks

(2024 > 04 - April > <2024-04-01 Mon>)

in 04/01/24 to 04/02/24, created 5 nodes

Author: Linfeng He

Created: 2024-04-05 Fri 02:38