Chapter 5
Tikz notes

5.1 Simple tikz examples
5.2 Generate SVG from tikz drawing
5.3 misc. notes
5.4 How to inlcude pdf file using tikz picture
5.5 Tikz documentation links
5.6 making loops
5.7 How to make aligned math inside a node?
5.8 trees with tikz?
5.9 more tikz examples

5.1 Simple tikz examples

Simple tikz examples

5.2 Generate SVG from tikz drawing

see page 117 in tikz manual 3.0

5.3 misc. notes

  1. tikz uses cm by default. a standard page in the US (letter) is 21.5 cm wide and 27.8 cm hight.

5.4 How to inlcude pdf file using tikz picture

\documentclass[11pt]{report} 
\usepackage{amsmath,mathtools} 
\usepackage{graphicx} 
\usepackage{pdfpages} 
\usepackage{tikz} 
\usepackage{pgffor} 
 
\begin{document} 
\pdfximage{file2.pdf} 
\foreach \index in {1,...,\the\pdflastximagepages} 
{ 
   \begin{tikzpicture}[remember picture] 
      \node[inner sep=0pt] at (current page.center) 
         {\includegraphics[page=\index]{file2.pdf}}; 
   \end{tikzpicture} 
} 
\end{document}
 

  1. tikz manual http://www.ctan.org/tex-archive/graphics/pgf/base/doc/generic/pgf/
  2. tikz-qtree http://www.ctan.org/pkg/tikz-qtree
  3. tikz-forest http://www.ctan.org/pkg/forest
  4. example qtree http://www.wikiprog.org/wiki/LaTeX:Arbre
  5. left and right trees http://tex.stackexchange.com/questions/44970/how-to-specify-left-and-right-node-of-a-tikz-qtree
  6. simple example of qtree with node http://tex.stackexchange.com/questions/43924/is-there-a-library-for-drawing-object-inheritance-trees-in-tikz

5.6 making loops

from http://pgf-and-tikz.10981.n7.nabble.com/Draw-a-shape-use-it-many-times-td4323.html

\documentclass{article} 
\input{commonlatex} 
\usepackage{tikz} 
\newcommand{\MyChair}{ 
\draw[fill=blue!15,thick] plot coordinates 
{(-2,-1)(-2,1)(-1,2)(2,3)(3,2)(3,-2)(2,-3)(-1,-2)}; 
\draw[fill=blue!15,thick] plot coordinates 
{(-2.5,-1)(-2.5,1)(-3.25,2)(-3.25,-2)}; 
} 
\begin{document} 
\begin{tikzpicture} [scale=0.125,smooth cycle] 
   \foreach \row in {1,2,...,10} 
   { 
       \foreach \col in {1,2,...,4} 
       { 
         \begin{scope}[xshift=\row cm,yshift=\col 10 cm] 
             \MyChair 
         \end{scope} 
       } 
   } 
\end{tikzpicture} 
\end{document}
 

5.7 How to make aligned math inside a node?

see http://tex.stackexchange.com/questions/1342/aligned-equations-inside-of-tikz-node

5.8 trees with tikz?

  1. examples http://mvngu.wordpress.com/2011/03/31/typeset-trees-using-tikzpgf/

5.9 more tikz examples

\documentclass{standalone} 
\usepackage{tikz} 
\usepackage{tikz-qtree} 
\begin{document} 
 
\tikzset{font=\small} 
 
\begin{tikzpicture} 
    \Tree [.A 
             [.\node(B){B}; ] 
             [.\node(C){C}; ] 
          ] 
\begin{scope}[xshift=0in,yshift=-2cm] 
    \Tree [.\node(Dx){D}; 
             [.E ] 
             [.F ] 
          ] 
\end{scope} 
 
\draw[-] (B) -- (Dx); 
\draw[-] (C) -- (Dx); 
\end{tikzpicture} 
\end{document}
 

PDF
\documentclass{standalone} 
\usepackage{tikz} 
\begin{document} 
\begin{tikzpicture} 
 
\draw [<->] (3,0) -- (0,0) -- (0,3); 
\draw (0,0) rectangle (3,3); 
\draw [fill=lightgray] (0,2.8)--(0,0)--(2.8,0); 
\node [font=\Huge] at (2,2) {$0$}; 
 
 
\end{tikzpicture} 
\end{document}
 

\documentclass{standalone} 
\usepackage{tikz} 
\begin{document} 
\begin{tikzpicture} 
 
\draw [very thin] (1,1) rectangle (2,2); 
\draw [<->] (3,0) -- (0,0) -- (0,3); 
 
 
\end{tikzpicture} 
\end{document}
 

\documentclass{standalone} 
\usepackage{tikz} 
\begin{document} 
\begin{tikzpicture} 
 
 \draw [<->] (3,0) -- (0,0) -- (0,3); 
 \draw [very thin] (1,1) rectangle (2,2); 
 \draw [fill=lightgray] (1,1)--(1.5,1)--(1,1.5); 
 
 
\end{tikzpicture} 
\end{document}
 

\documentclass{standalone} 
\usepackage{tikz} 
\begin{document} 
\begin{tikzpicture} 
 
 \def\x{0}% 
  \def\y{0}% 
   \draw [very thin] (\x,\y) rectangle (\x+2,\x+2); 
   \draw [fill=lightgray] (\x,\y)--(\x+1.75,\y+0)--(\x+0,\y+1.75); 
   \node[font=\Huge] at (\x+1.25,\y+1.25) {$0$}; 
   \node at (\x+2.25,\y+1) {$+$}; 
 
\end{tikzpicture} 
\end{document}
 

\documentclass{standalone} 
\usepackage{tikz} 
\begin{document} 
\begin{tikzpicture} 
  \path[draw] (0,0) rectangle (2,1); 
\end{tikzpicture} 
\end{document}
 

PDF
\documentclass{standalone} 
\usepackage{tikz} 
\begin{document} 
\begin{tikzpicture} 
  \path[fill,draw] (0,0) rectangle (2,1); 
\end{tikzpicture} 
\end{document}
 

PDF
\documentclass{standalone} 
\usepackage{tikz} 
\begin{document} 
\begin{tikzpicture} 
  \path[shade,draw] (0,0) rectangle (2,1); 
\end{tikzpicture} 
\end{document}
 

PDF
\documentclass{standalone} 
\usepackage{tikz} 
\begin{document} 
\begin{tikzpicture} 
  \path[shade,top color=yellow!80!black, 
        bottom color=white,draw] (0,0) rectangle (2,1); 
\end{tikzpicture} 
\end{document}
 

PDF
\documentclass{standalone} 
\usepackage{tikz} 
\usetikzlibrary{trees} 
\begin{document} 
\begin{tikzpicture} 
  \node {A} 
      [edge from parent fork down] 
      child {node {B}} 
      child {node {C}} 
   ; 
\end{tikzpicture} 
\end{document}
 

PDF
\documentclass{standalone} 
\usepackage{tikz} 
\usetikzlibrary{trees} 
\begin{document} 
\tikzset{every node/.style={draw, 
                            rectangle, 
                            rounded corners 
                           } 
        } 
 
\begin{tikzpicture} 
  \node {A} 
      [edge from parent fork down] 
      child {node {B}} 
      child {node {C}} 
   ; 
\end{tikzpicture} 
\end{document}
 

PDF
\documentclass{standalone} 
\usepackage{tikz} 
\usetikzlibrary{trees} 
\begin{document} 
 
\tikzset{level 1/.style={sibling distance=2cm}, 
         level 2/.style={sibling distance=1cm}} 
 
\begin{tikzpicture} 
  \node {A} 
      [edge from parent fork down] 
      child {node {B} 
         child {node {B1}} 
      } 
      child {node {C} 
         child {node {C1}} 
         child {node {C2}} 
         child {node {C3}} 
      } 
   ; 
\end{tikzpicture} 
\end{document}
 

PDF
see http://tex.stackexchange.com/questions/124862/how-to-draw-a-d iagram-that-forks-out-then-joins-in-the-middle-then-forks-out-ag
%written by Qrrbrbirlbel at Tex stackexchange 
\documentclass[tikz]{standalone} 
\usetikzlibrary{positioning-plus,paths.ortho} 
\tikzset{ 
  parents/.style 2 args={ 
     @parents/.style={insert path={edge[edge from children path] (#1-##1)}}, 
     @parents/.list={#2}}, 
  edge from parent path={ 
    (\tikzparentnode\tikzparentanchor) |-| (\tikzchildnode\tikzchildanchor)}, 
  edge from children path/.style={ 
    to path={ 
      (\tikztostart\tikzchildanchor) |-| (\tikztotarget\tikzparentanchor) \tikztonodes}} 
} 
\begin{document} 
\begin{tikzpicture}[ 
  node distance=\tikzleveldistance and \tikzsiblingdistance, 
  on grid, 
  text depth=+0pt, 
  hvvh=from center 
  ] 
 
\node (A) {A} 
  child {node {B}} 
  child {node {C}}; 
\node[below=2:of A] (E) {E} [parents={A}{1,2}] 
  [sibling distance/.expanded=2*\the\tikzsiblingdistance] 
  child {node {F} 
    child {coordinate 
      [anchor=center,sibling distance/.expanded=.5*\the\tikzsiblingdistance] 
      child {node {N}} 
      child {node {Q}} 
    } 
    child {node {R}} 
  } 
  child {node {G}} 
  child {node {H}}; 
 
\node[below=of (E-2)(E-3)] (L) {L} [parents={E}{2,3}] 
  child {node {M}} 
  child {node {N}} 
  child {node {K}} 
; 
\end{tikzpicture} 
\end{document}
 

PDF