I want to build a tree of the 8-puzzle. By using logicpuzzle and forest I got to this point:
\documentclass{article}
\usepackage{logicpuzzle}
\usepackage{forest}
\newenvironment{eight}[1][]{%
\begin{logicpuzzle}[rows=3,columns=3,#1]
\begin{puzzleforeground}
\framepuzzle
\end{puzzleforeground}
}{\end{logicpuzzle}}
\begin{document}
\begin{forest}
[\begin{eight}
\setrow{3}{1,4,2}
\setrow{2}{6,,5}
\setrow{1}{7,3,8}
\end{eight}
[\begin{eight}
\setrow{3}{1,4,2}
\setrow{2}{,6,5}
\setrow{1}{7,3,8}
\end{eight}
\begin{eight}
\setrow{3}{1,,2}
\setrow{2}{6,4,5}
\setrow{1}{7,3,8}
\end{eight}
\begin{eight}
\setrow{3}{1,4,2}
\setrow{2}{6,5,}
\setrow{1}{7,3,8}
\end{eight}
\begin{eight}
\setrow{3}{1,4,2}
\setrow{2}{6,3,5}
\setrow{1}{7,,8}
\end{eight}]]
\end{forest}
\end{document}
But the result I get has these problems:
- The numbers don't appear inside the grid
- The lines connecting the starting configuration to the next four are not displayed correctly
- The whole drawing is shifted to the right and gets out of the page


tikzpictureenvironments, see this question. 2) Missing lines connecting forest nodes are caused by wrong usage: it should be[A [B][C][D][E]], not[A [B C D E]]. 3) Shifted drawing could be the combination of page margin, too long drawing, and forest node separation and anchors. If all you want is several connected 3x3 matrixes, then manually draw them in tikz (to get rid of the nesting issue) could be a workaround.