我正在尝试创建类似于下面所示的井字游戏板图。
我似乎找不到任何关于如何在 LaTeX 或 TikZ 中创建这些板的文档或示例。有人知道这种图表的解决方案吗?
答案1
这远非完美,但可以完成工作,不过,我会使用其他连接。
代码
\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\\\hline#7	
\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}