Archive

Posts Tagged ‘LaTeX’

Typeset trees using TikZ/PGF

31 March 2011 Leave a comment

Some combinatorial trees typeset using TikZ/PGF. The Linux filesystem hierarchy:

The Linux filesystem hierarchy.

\begin{tikzpicture}
[-,thick]
\footnotesize
\node {\texttt{/}} [edge from parent fork down]
  child {node {\texttt{bin}}}
  child {node {\texttt{etc}}}
  child {node {\texttt{home}}
    child {node {\texttt{anne}}}
    child {node {\texttt{sam}}}
    child {node {$\dots$}}
  }
  child {node {\texttt{lib}}}
  child {node {\texttt{opt}}}
  child {node {\texttt{proc}}}
  child {node {\texttt{tmp}}}
  child {node {\texttt{usr}}
    child {node {\texttt{bin}}
      child {node {\texttt{acyclic}}}
      child {node {\texttt{diff}}}
      child {node {\texttt{dot}}}
      child {node {\texttt{gc}}}
      child {node {\texttt{neato}}}
      child {node {$\dots$}}
    }
    child {node {\texttt{include}}}
    child {node {\texttt{local}}}
    child {node {\texttt{share}}}
    child {node {\texttt{src}}}
    child {node {$\dots$}}
  }
  child {node {$\dots$}};
\end{tikzpicture}

Classification tree of organisms:
Classification tree of organisms.

\begin{tikzpicture}
[sibling distance=6cm,-,thick]
\footnotesize
\node {organism}
  child {node {plant}
    [sibling distance=2cm]
    child {node {tree}
      child {node {deciduous}}
      child {node {evergreen}}
    }
    child {node {flower}}
  }
  child {node {animal}
    [sibling distance=2.5cm]
    child {node {invertebrate}}
    child {node {vetebrate}
      [sibling distance=4.7cm]
      child {node {bird}
        [sibling distance=1.5cm]
        child {node {finch}}
        child {node {rosella}}
        child {node {sparrow}}
      }
      child {node {mammal}
        [sibling distance=1.5cm]
        child {node {dolphin}}
        child {node {human}}
        child {node {whale}}
      }
    }
  };
\end{tikzpicture}

The Bernoulli family tree of mathematicians:
Bernoulli family tree of mathematicians.

\begin{tikzpicture}
[-,thick,%
  every node/.style={shape=rectangle,inner sep=3pt,draw,thick}]
\footnotesize
\node {Nikolaus senior} [edge from parent fork down]
  [sibling distance=4cm]
  child {node {Jacob}}
  child {node {Nicolaus}
    child {node {Nicolaus I}}
  }
  child {node {Johann}
    [sibling distance=2cm]
    child {node {Nicolaus II}}
    child {node {Daniel}}
    child {node {Johann II}
      child {node {Johann III}}
      child {node {Daniel II}}
      child {node {Jakob II}}
    }
  };
\end{tikzpicture}

An expression tree:

Expression tree for the perfect square identity.

\begin{tikzpicture}
[-,thick]
\node {$+$}
  [sibling distance=2.5cm]
  child {node {$\times$}
    [sibling distance=1cm]
    child {node {$a$}}
    child {node {$a$}}
  }
  child {node {$\times$}
    [sibling distance=1cm]
    child {node {$2$}}
    child {node {$a$}}
    child {node {$b$}}
  }
  child {node {$\times$}
    [sibling distance=1cm]
    child {node {$b$}}
    child {node {$b$}}
  };
\end{tikzpicture}

Simple graphs, bridges of Konigsberg and directed graphs

26 March 2011 Leave a comment

Some combinatorial graphs drawn using TikZ/PGF. The seven bridges of Konigsberg:

Seven bridges of Konigsberg

\begin{tikzpicture}
[lineDecorate/.style={-,thick},%                                                
  nodeDecorate/.style={shape=circle,inner sep=2pt,draw,thick}]
%% nodes or vertices                                                            
\foreach \nodename/\x/\y/\direction/\navigate in {
  a/0/0/left/west, b/0/2/left/west, c/0/4/left/west, d/4/2/right/east}
{
  \node (\nodename) at (\x,\y) [nodeDecorate] {};
  \node [\direction] at (\nodename.\navigate) {\footnotesize$\nodename$};
}
%% edges or lines                                                               
\path
\foreach \startnode/\endnode in {a/d, b/d, c/d}
{
  (\startnode) edge[lineDecorate] node {} (\endnode)
}
\foreach \startnode/\endnode in {a/b, b/c, c/b, b/a}
{
  (\startnode) edge[lineDecorate,bend left] node {} (\endnode)
};
\end{tikzpicture}

A house graph:

House graph

\begin{tikzpicture}
[lineDecorate/.style={-,thick},%                                                
  nodeDecorate/.style={shape=circle,inner sep=2pt,draw,thick}]
%% nodes or vertices                                                            
\foreach \nodename/\x/\y/\direction/\navigate in {
  a/0/5/above/north, b/2/3/right/east, e/-2/3/left/west,
  c/2/0/right/east, d/-2/0/left/west}
{
  \node (\nodename) at (\x,\y) [nodeDecorate] {};
  \node [\direction] at (\nodename.\navigate) {\footnotesize$\nodename$};
}
%% edges or lines                                                               
\path
\foreach \startnode/\endnode in {a/b, b/c, b/e, c/d, d/e, e/a}
{
  (\startnode) edge[lineDecorate] node {} (\endnode)
};
\end{tikzpicture}

A weighted multigraph:
Weighted multigraph

\begin{tikzpicture}
[nodeDecorate/.style={shape=circle,inner sep=1pt,draw,thick}]
%% nodes or vertices                                                            
\foreach \nodename/\x/\y in {v_1/4/0, v_2/0/0, v_3/0/3, v_4/4/3, v_5/7/1.5}
{
  \node (\nodename) at (\x,\y) [nodeDecorate] {\scriptsize$\nodename$};
}
%% edges or lines                                                               
\tikzstyle{EdgeStyle}=[->,>=stealth,thick]
\tikzstyle{LabelStyle}=[fill=white]
\foreach \startnode/\endnode/\bend/\weight in {
  v_1/v_2/bend left/1, v_1/v_3/bend left/3, v_2/v_3/bend left/1,
  v_2/v_4/bend left/3, v_3/v_1/bend left/1, v_3/v_2/bend left=0/2,
  v_3/v_4/bend left/1, v_4/v_1/bend left=0/3, v_4/v_5/bend left/2,
  v_5/v_1/bend left=0/3, v_5/v_1/bend left/6, v_5/v_4/bend left/1}
{
  \scriptsize
  \Edge[label=$\weight$,style=\bend](\startnode)(\endnode)
}
\end{tikzpicture}

QED symbol for end of proof

24 November 2010 Leave a comment

The amssymb \LaTeX package defines a default Halmos symbol that automatically appears when you use the proof environment. That default Halmos symbol is \Box. But if you want that to be filled with black, you could redefine the Halmos symbol. Put the following in your preamble:

\renewcommand{\qed}{\hfill \mbox{\raggedright \rule{0.1in}{0.1in}}}

Better still, you could customize what symbol you want to use as your QED symbol. Just replace the macro \rule{0.1in}{0.1in} with the the symbol of your choice.

Follow

Get every new post delivered to your Inbox.