答案1
\documentclass{article}
\usepackage{logicpuzzle}
\newenvironment{fifteen}[1][]{%
\begin{logicpuzzle}[rows=4,columns=4,#1]
\begin{puzzleforeground}
\framepuzzle
\end{puzzleforeground}
}{\end{logicpuzzle}}
\begin{document}
\begin{fifteen}
\setrow{4}{13,10,11,6}
\setrow{3}{5,7,4,8}
\setrow{2}{1,12,14,9}
\setrow{1}{3,15,2,}
\end{fifteen}
%
\begin{fifteen}
\setrow{4}{13,10,11,6}
\setrow{3}{1,5,7,4}
\setrow{2}{3,12,14,8}
\setrow{1}{,15,2,9}
\end{fifteen}
\end{document}
答案2
这会将列表放入足够大的最小二次网格中以容纳它。
\documentclass{article}
\usepackage{tikz}
\newcommand{\Puzzle}[2][]{\begin{tikzpicture}
\pgfmathtruncatemacro{\mydim}{dim({#2})}%
\pgfmathtruncatemacro{\myrows}{sqrt(\mydim)+0.99}%
\pgfmathtruncatemacro{\mymax}{max(#2)}%
\pgfmathsetmacro{\mysize}{width("\mymax")+8}%
\draw (0,0) grid[step=\mysize pt] (\myrows*\mysize pt,-\myrows*\mysize pt);
\foreach \Z [count=\Cn starting from 0] in {#2}
{\pgfmathtruncatemacro{\Y}{\Cn/\myrows}%
\pgfmathtruncatemacro{\X}{\Cn-\Y*\myrows}%
\unless\ifnum\Z<0
\node[minimum size=\mysize pt,anchor=north west] at (\X*\mysize pt,-\Y*\mysize pt) {\Z};
\fi}
\end{tikzpicture}}
\begin{document}
\Puzzle{13,10,11,6,5,7,4,8,1,12,14,9,3,15,2}
\Puzzle{13,10,11,6,5,7,4,8,1,12,14,9,3,15,2,13,10,11,6,5,7,4,8,1,12,14,9,3,15,2,3,4}
\Puzzle{13,10,-1,11,6,-1,5}
\end{document}
答案3
以下是我的答案的一个简化版本:表格环境中固定高度行中的垂直居中材料
\documentclass{article}
\newcount\cellwd
\newcount\cellht
\makeatletter
{\catcode`|=\active \gdef|{\acell}}
\newcommand\acell[1]{\noindent%
\framebox(\cellwd,\cellht){\centering#1}\kern\@wholewidth\ignorespaces}
\newcommand\cellrowskip{\\[\dimexpr-1pt+\@wholewidth\relax]}
\newenvironment{celltable}[2][\@wholewidth]
{\cellwd=#2\relax
\cellht=#2\relax
\linethickness{#1}%
\vspace{#1}%
\par\catcode`\| \active
}{\par}
\makeatother
\begin{document}
What precedes.
\begin{celltable}{30}% CELL SIZE IN PT
|{13}|{10}|{11}|6\cellrowskip
|5|7|4|8\cellrowskip
|1|{12}|{14}|9\cellrowskip
|3|{15}|2|~
\end{celltable}
What follows.
\end{document}
当然,如果单元格大小不重要,那么简单的方法tabular
就可以了:
\documentclass{article}
\begin{document}
What precedes.
\begin{tabular}{|c|c|c|c|}
\hline
13 & 10 & 11 & 6\\
\hline
5 & 7 & 4 & 8\\
\hline
1 & 12 & 14 & 9\\
\hline
3 & 15 & 2 &\\
\hline
\end{tabular}
What follows.
\end{document}