[Tex/LaTex] Using TikZ for a simple drawing

tikz-pgf

How do you draw a simple figure like the following in TikZ? It seems like the only way to start learning TikZ is by adopting examples, but I found the only two fairly relevant to what I wanted too complicated for what I am trying to achieve here. What I am trying to accomplish by getting a piece of code for this figure, is not only the figure itself, but also insight in how TikZ does drawings like these, so I can use it to make similar figures in the future.

enter image description here

Best Answer

Actually this is rather simple. There are several ways to do it. One way would be to place the first node using \node (NAME) at (POSITION) {TEXT}; and then further nodes using \node (NAME) [below left=Y and X of NODE] {TEXT}; etc.. Arrows can be drawn using \draw [->] (NODE1) -- (NODE2);. Add a trailing node [OPTIONS] {TEXT} before the ; to add labels to the arrows.

\documentclass{standalone}% For the example only, any class will do

\usepackage{tikz}
\usetikzlibrary{positioning}% To get more advances positioning options
\usetikzlibrary{arrows}% To get more arrow heads

\begin{document}
\begin{tikzpicture}[>=triangle 45,font=\sffamily]
    \node (X) at (0,0) {x};
    \node (Y) [below left=2cm and 1cm of X]  {y};% 2cm below, 1cm to the left (optional)
    \node (Z) [below right=2cm and 1cm of X] {z};
    \node (U) [below left=2cm and 1cm of Z]  {u};
    \draw [semithick,->] (X) -- (Y);
    \draw [semithick,->] (X) -- (Z);
    \draw [semithick,->] (Y) -- (U) node [midway,below,sloped] {*};
    \draw [semithick,->] (Z) -- (U) node [midway,below,sloped] {*};
\end{tikzpicture}
\end{document}

Diagram