# How to create simple causal chains with TikZ

I have a problem trying to create a simple causal chain, as it can be seen on the attached file: List of available TikZ libraries with a short introduction.

I'm having two main issues:

1. I would like to remove the "clouds" from X and Y.
2. The arrow from Z should hit perpendicularly the arrow from X to Y.

I have spent hours trying to solve them, but without luck.

Here is my MWE so far:

\documentclass{article}
\usepackage{tikz}
\usepackage{pgf}
\usetikzlibrary{shapes,arrows}
%
\begin{document}
%
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, ellipse, node distance=3cm, minimum height=2em]
\begin{tikzpicture}[node distance = 3cm, auto]
\node [cloud] (init) {Z1};
\node [blank, below of=init] (sup) {};
\node [cloud, left of=X1] (X1) {X1};
\node [cloud, right of=Y1] (Y1) {Y1};
\path [line] (X1) -- (Y1);
\path [line] (init) -- (sup);
\end{tikzpicture}
%
\end{document}


Here is the output:

The wanted image should appear like this:

• Can you show us some of the code of your attempts so we can see where the problem is? – doncherry Nov 24 '13 at 22:40
• I am sorry. I have now edited my post, so you can see how it looks like in my document. – A. F. Nov 24 '13 at 22:51
• I have now added an extra photo. Maybe it helps. – A. F. Nov 24 '13 at 22:53
• It should be there now. – A. F. Nov 24 '13 at 22:57
• @Jake: Sure, done … thanks for the reminder :-) I deleted my comment too. – Tobi Nov 25 '13 at 8:55

Other solution, also using TikZ.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[%
>=latex',
circ/.style={draw, shape=circle, node distance=1cm, line width=1pt}]%Define the arrow type and style for circled nodes
\draw[->] (0,0) node[left] (X) {X} -- (2,0) node[right] (Y) {Y}; %Line between X and Y
\path (X) -- coordinate (middle) (Y);%Defining the middle between X and Y
\node[above of=middle,circ] (Z) {Z};%Draw Z, a circled node
\draw[->] (Z) -- (middle);%Line between Z and X-Y
\end{tikzpicture}
\end{document}


Result

If you want to use a ellipse or another shape:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes}
\begin{document}

%With a ellipse
\begin{tikzpicture}[%
>=latex',
cloud/.style={draw, thick, shape=ellipse, node distance=1cm, minimum width=0.8cm}]%Define the arrow type and style for ellipse nodes
\draw[->,thick] (0,0) node[left] (X) {X} -- (2,0) node[right] (Y) {Y}; %Line between X and Y
\path (X) -- coordinate (middle) (Y);%Defining the middle between X and Y
\node[above of=middle,cloud] (Z) {Z};%Draw Z, a circled node
\draw[->,thick] (Z) -- (middle);%Line between Z and X-Y
\end{tikzpicture}

%With a rectangle
\begin{tikzpicture}[%
>=latex',
block/.style={rectangle,draw,thick,node distance=1cm,rounded corners}]%Define the arrow type and style for retangular nodes
\draw[->,thick] (0,0) node[left] (X) {X} -- (2,0) node[right] (Y) {Y}; %Line between X and Y
\path (X) -- coordinate (middle) (Y);%Defining the middle between X and Y
\node[above of=middle,block] (Z) {Z};%Draw Z, a circled node
\draw[->,thick] (Z) -- (middle);%Line between Z and X-Y
\end{tikzpicture}
\end{document}


You have some mistakes.

1. There is no blank option for nodes.
2. In \node [cloud, left of=X1] (X1) {X1};, left of=X1 is wrong as X1 is unknown at this point. Further, you are saying left of hence the X1 comes to the left at the same height. It should be below left = of init. Same is true for \node [cloud, right of=Y1] (Y1) {Y1}; You may refer to this question.
3. With calc library, you can find the mid point of the line joing X1 and Y1. Hence you won't need \node [coordinate,below of=init] (sup) {};.
4. Don't use \tikstyle, use \tikzset instead. Refer to this question.

Full code with correction:

\documentclass[a4paper,12pt,oneside]{article}
\usepackage{tikz}
\usepackage{pgf}
\usetikzlibrary{shapes,arrows,positioning,calc}  %% Added last two libraries
\begin{document}
%% Use tikzset instead of tikzstyle which is deprecated
\tikzset{line/.style = {draw, -latex'},
cloud/.style = {draw, ellipse, node distance=3cm,
minimum height=2em}
}
\begin{tikzpicture}[node distance = 3cm, auto]
\node [cloud] (init) {Z1};
%\node [coordinate,below of=init] (sup) {}; not needed
\node [cloud, below left = of init] (X1) {X1};  %% note below left syntax from positioning library
\node [cloud, below right = of init] (Y1) {Y1};

\path [line] (X1) -- (Y1);   %% (($(X1)!0.5!(Y1)$) is mdpoint of this line
\path [line] (init) -- ($(X1)!0.5!(Y1)$);  %% $expression$ possible with calc library
\end{tikzpicture}
\end{document}


If you don't want ellipse surrounding X1 and Y1, remove cloud option from them:

\node [below left = of init] (X1) {X1};
\node [below right = of init] (Y1) {Y1};


to get

Also, if X1 and Y1 are math symbols/variables, don't forget to surround them with ${$X1$}; As Marc notes in the comments, you can avoid calc library by using \path[line] (init) -- (init -| X1);. • A helpful reference for point 2 is: tex.stackexchange.com/questions/9386/… – Adam Liter Nov 24 '13 at 23:21 • @Adam Thanks for the link. I added it in the answer. :-) – user11232 Nov 24 '13 at 23:27 • You can also draw the last arrow without the calc library: (init) -- (init -| X1). – user10274 Nov 25 '13 at 10:26 • @MarcvanDongen You are right :-) – user11232 Nov 25 '13 at 12:23 • Hi Harish Kumar. Thank you for a very helpful answer. If I would like to change names of Z1, X1 and Y1, should I just replace the names? Or? Because I can see the line from Z1 wouldn't be straight ? – A. F. Nov 25 '13 at 17:55 Your code is quite confusing. Is this what you wanted? \documentclass[tikz]{standalone} \usepackage{tikz} \usepackage{pgf} \begin{document} \usetikzlibrary{shapes, calc, positioning} \begin{tikzpicture} %create X and Y node \node (X) {X}; \node [right = 1.5 of X] (Y) {Y}; %create a coordinate in the middle of (X) and (Y) \coordinate (middle) at ($(X)!0.5!(Y)$); %draw Z above this middle %add "\," before and after Z to add some space, so that you get a nice ellipse \node[ellipse, draw, above = .5 of middle] (Z) {\,Z\,}; %draw arrow between (X) and (Y) \draw (X) edge[->] (Y); %draw arrow from (Z) to 1pt above (middle) \draw(Z) edge[->] ($(middle)+(0,1pt)\$);
\end{tikzpicture}

\end{document}


results in: