# Creating Tic-Tac-Toe boards with LaTeX/TikZ

I am trying to create a diagram of tic-tac-toe boards similar to the one attached below.

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?

-
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

## 1 Answer

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

## Code

\documentclass[tikz]{standalone}
\usepackage{forest,calc}
\forestset{
make tab/.style args={#1:#2:#3/#4:#5:#6/#7:#8:#9}{%
content={%
\tabcolsep=.6\tabcolsep
\begin{tabular}{p{\widthof{x}}|p{\widthof{x}}|p{\widthof{x}}}
#1 & #2 & #3\\\hline#4&#5&#6\\\hline#7&#8&#9
\end{tabular}}},
label position r/.initial=right,
label position b/.initial=below
}
\begin{document}
\begin{forest}
TTT/.style args={#1:#2}{
make tab/.expanded=\forestove{content},
label={\pgfkeysvalueof{/forest/label position #1}:$#2$}
},
TTT*/.style={
make tab=::/::/::,
content/.expand once=%
\expandafter\vphantom\expandafter{\romannumeral-0\forestov{content}},
draw=none,
append after command={(\tikzlastnode.north) edge (\tikzlastnode.south)},
for descendants={before computing xy={l*=1.2}},
},
th/.style=thick,
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]
]
]
\end{forest}
\end{document}
`

-