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?

  • 2
    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? 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.
    – user19598
    Oct 20 '13 at 21:39
  • 1
    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!
    – user19598
    Oct 20 '13 at 21:47
  • 1
    Drawing a tree of grids Oct 21 '13 at 5:41

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy