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 am trying to create a diagram of tic-tac-toe boards similar to the one attached below.

tic-tac-toe boards

I cannot seem to find any documentation or examples on how to create these boards in LaTeX or TikZ. Does anyone know of a solution for this sort of diagram?

share|improve this question
You can make trees with TikZ, forest or many other packages. You can do these boards inside TikZ with matrices, tabulars or manually. Anything tried already? – Qrrbrbirlbel Oct 20 '13 at 21:17
I have made trees in TikZ in the past, and I am currently reading up on tables in TikZ, but I am still unsure how to combine the two. That is, how do I replace the nodes of the tree with the tables themselves? Thank you for your response. – user41419 Oct 20 '13 at 21:39
When you write \node {...} between the brackets you can put pretty much anything, even tables and nested tikzpicture environment (useful here if you want really fine control on how the tables are typeset). – Bordaigorl Oct 20 '13 at 21:46
Interesting. I didn't know that! I will give this a try then. Thanks! – user41419 Oct 20 '13 at 21:47
Drawing a tree of grids – Tom Bombadil Oct 21 '13 at 5:41
up vote 11 down vote accepted

This is far from perfect but does the job, though, I would use other connections.


  make tab/.style args={#1:#2:#3/#4:#5:#6/#7:#8:#9}{%
        #1 & #2 & #3\\\hline#4&#5&#6\\\hline#7&#8&#9
  label position r/.initial=right,
  label position b/.initial=below
  TTT/.style args={#1:#2}{
    make tab/.expanded=\forestove{content},
    label={\pgfkeysvalueof{/forest/label position #1}:$#2$}
    make tab=::/::/::,
    content/.expand once=%
    append after command={(\tikzlastnode.north) edge (\tikzlastnode.south)},
    for descendants={before computing xy={l*=1.2}},
  for tree={node options=draw, inner sep=+0pt, parent anchor=south, child anchor=north}
[::/::/::, TTT=r:1
 [x::/::/::, TTT=r:-1
   [x:o:/::/::, TTT=b: 1, th]
   [x::/:o:/::, TTT=b:-1]
   [x::o/::/::, TTT=b: 0, th]
   [x::/::/::o, TTT=b: 0, th]
   [x::/::o/::, TTT=b: 1, th]
 [::/:x:/::, TTT=r:1,
   [,TTT* % this is just cheating :(
    [o::/:x:/::, TTT=b:1]
    [:o:/:x:/::, TTT=b:2]
 [:x:/::/::, TTT=r:-2
   [:x:o/::/::, TTT=b:-1, th]
   [:x:/:o:/::, TTT=b:-2]
   [:x:/::/:o:, TTT=b: 0, th]
   [:x:/::/o::, TTT=b:-1, th]
   [:x:/o::/::, TTT=b: 0, th]


enter image description here

share|improve this answer

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.