TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need help to draw a Directed Acyclic Graph of Bayesian Network along with probability of each node using TikZ package. Here is an example:

enter image description here

Table grid can be a full or partial as in above example.

share|improve this question
You can put an entire tabular environment inside a tikz node, so you can integrate your tables in the tikz figure. It is all about node placement. Use positioning library. – JLDiaz Feb 27 '13 at 23:33
This is very similar to Balanced Scorecard diagram. If you're not hooked on tikz, then the code could be adapted to produce the required output. – Werner Feb 27 '13 at 23:43
up vote 3 down vote accepted

I am in a good mood to provide you with a minimal working example (MWE) but in future questions, I advise you to provide one. (Summer break for teachers here :) See for instance: "Just do it for me" text building block

Here it is in tikz. You can do the rest for practice. See the pgfmanual. You can also type texdoc pgf in your terminal or command line.

Here are some explanations.

  • Usually, node commands are done as follows: \node (<node name>) [<options>] {<text>};
  • Edit: The positioning library enables you to specify how far the location of nodes/coordinates relative to other nodes/coordinates. Reference: Package PGF Math Error: Unknown operator `o' or `of'
  • The arrows library allows you to use other types of arrows aside from the default of >.
  • The shapes library allows usage of shapes like ellipse for nodes.

The partial code

\documentclass[border=5, convert={density=150}]{standalone}

\usetikzlibrary{shapes, arrows}
    events/.style={ellipse, draw, align=center},
\begin{tikzpicture}[node distance=2cm, >=stealth']
\node [events] (cloudy) {Cloudy};
\node [events, below left = of cloudy] (sprinkler) {Sprinkler};
\node [events, below right = of cloudy] (rain) {Rain};
\node [events, below right = of sprinkler] (wetgrass) {WetGrass};

\draw [->] (cloudy) -- (sprinkler);
\draw [->] (cloudy) -- (rain);
\draw [->] (rain) -- (wetgrass);
\draw [->] (sprinkler) -- (wetgrass);

\node [above = of cloudy] {
    \mathrm{P(C=F)} & \mathrm{P(C=T)}\\
    0.5 & 0.5\\

\node [right = of rain, anchor=west] {
    C & \mathrm{P(C=F)} & \mathrm{P(C=T)}\\
    F & 0.8 & 0.2\\
    T & 0.2 & 0.8\\


The output

enter image description here

share|improve this answer
Thanks a lot, you are a gentle man. – user986789 Feb 28 '13 at 8:52
Your example even runs without positioning. The syntax for positioning is …=… of …, see Package PGF Math Error: Unknown operator o or of. The … of=… syntax is actually deprecated, see Difference between "right of=" and "right=of" in PGF/TikZ. – Qrrbrbirlbel Feb 28 '13 at 13:27
@Qrrbrbirlbel I knew there was something off. That is why I had to drop by here early. Thanks a lot! – hpesoj626 Feb 28 '13 at 21:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.