为 S Lloyd 的“从克朗代克回来”问题排版截断棋盘

为 S Lloyd 的“从克朗代克回来”问题排版截断棋盘

我正在尝试用 LaTeX 创建一个如下所示的表格: 在此处输入图片描述

从问题从克朗代克归来 我所能做的最好的就是

\documentclass[10pt]{article}
\begin{document}

\begin{table}[!h]
\begin{tabular}{*{21}{c}}
%\begin{tabular}{*{21}{c@{\hspace{1.25\tabcolsep}}}}
\cline{10-12}   & & & & & & & & &4&7&7& & & & & & & & &  \\
\cline{7-15}    & & & & & &5&4&4&8&3&3&4&6&3& & & & & &  \\
\cline{5-17}    & & & &1&4&5&1&1&1&4&5&1&7&1&3&5& & & &  \\
\cline{4-18}    & & &4&9&4&9&6&7&5&5&5&8&7&6&6&8&5& & &  \\
\cline{3-19}    & &3&7&2&9&8&3&5&6&7&3&9&1&8&7&5&8&5& &  \\
\cline{3-19}    & &1&4&7&8&4&2&9&2&7&1&1&8&2&2&7&6&3& &  \\
\cline{2-20}    &7&2&1&8&5&5&3&1&1&3&1&3&3&4&2&8&6&1&3&  \\
\cline{2-20}    &4&2&6&7&2&5&2&4&2&2&5&4&3&2&8&1&7&7&3&  \\
\cline{2-20}    &4&1&6&5&1&1&1&9&1&4&3&4&4&3&1&9&8&2&7&  \\
\cline{1-21}   4&3&5&2&3&2&2&3&2&4&2&5&3&5&1&1&3&5&5&3&7 \\
\cline{1-21}   2&7&1&5&1&1&3&1&5&3&3&2&4&2&3&7&7&5&4&2&7 \\
\cline{1-21}   2&5&2&2&6&1&2&4&4&6&3&4&1&2&1&2&6&5&1&8&8 \\
\cline{1-21}    &4&3&7&5&1&9&3&4&4&5&2&9&4&1&9&5&7&4&8&  \\
\cline{2-20}    &4&1&6&7&8&3&4&3&4&1&3&1&2&3&2&3&6&2&4&  \\
\cline{2-20}    &7&3&2&6&1&5&3&9&2&3&2&1&5&7&5&8&9&5&4&  \\
\cline{2-20}    & &1&6&7&3&4&8&1&1&1&2&1&2&2&8&9&4&1& &  \\
\cline{3-19}    & &2&5&4&7&8&7&5&6&1&3&5&7&8&7&2&9&3& &  \\
\cline{3-19}    & & &6&5&6&4&6&7&2&5&2&2&6&3&4&7&4& & &  \\
\cline{4-18}    & & & &2&3&1&2&3&3&3&2&1&3&2&1&1& & & &  \\
\cline{5-17}    & & & & & &7&4&4&5&7&3&4&4&7& & & & & &  \\
\cline{7-15}    & & & & & & & & &3&3&4& & & & & & & & &  \\
\cline{10-12}   & & & & & & & & & & & & & & & & & & & &   
\end{tabular}                       
\end{table}
\end{document}

它太丑了,我不会发布它:水平间距完全错误(而且我似乎无法使用来修复它1.25\tabcolsep);没有垂直线;并且缺少棋盘背景。

理想情况下,我还可以添加从特定坐标到另一个坐标的箭头来指示解决方案。

任何帮助,将不胜感激!

答案1

matrix您可以使用包中的库来简单绘制截止检查板tikz

\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}


\begin{document}
    \begin{tikzpicture}
\matrix [matrix of nodes,
         nodes={draw, minimum size=1.5em, 
                fill=teal!50, text=white, font=\large,
                inner sep=0pt,outer sep=0pt, 
                anchor=center},
         every even  column/.style={every odd row/.append style={nodes={fill=black, text=white}}},
         every odd  column/.style={every even row/.append style={nodes={fill=black, text=white}}},
         column sep=-\pgflinewidth,
         row sep=-\pgflinewidth
         ]
{   & & & & & & & & &4&7&7& & & & & & & & &  \\
    & & & & & &5&4&4&8&3&3&4&6&3& & & & & &  \\
    & & & &1&4&5&1&1&1&4&5&1&7&1&3&5& & & &  \\
    & & &4&9&4&9&6&7&5&5&5&8&7&6&6&8&5& & &  \\
    & &3&7&2&9&8&3&5&6&7&3&9&1&8&7&5&8&5& &  \\
    & &1&4&7&8&4&2&9&2&7&1&1&8&2&2&7&6&3& &  \\
    &7&2&1&8&5&5&3&1&1&3&1&3&3&4&2&8&6&1&3&  \\
    &4&2&6&7&2&5&2&4&2&2&5&4&3&2&8&1&7&7&3&  \\
    &4&1&6&5&1&1&1&9&1&4&3&4&4&3&1&9&8&2&7&  \\
   4&3&5&2&3&2&2&3&2&4&2&5&3&5&1&1&3&5&5&3&7 \\
   2&7&1&5&1&1&3&1&5&3&\textcolor{red}{\textbf{3}}
                        &2&4&2&3&7&7&5&4&2&7 \\
   2&5&2&2&6&1&2&4&4&6&3&4&1&2&1&2&6&5&1&8&8 \\
    &4&3&7&5&1&9&3&4&4&5&2&9&4&1&9&5&7&4&8&  \\
    &4&1&6&7&8&3&4&3&4&1&3&1&2&3&2&3&6&2&4&  \\
    &7&3&2&6&1&5&3&9&2&3&2&1&5&7&5&8&9&5&4&  \\
    & &1&6&7&3&4&8&1&1&1&2&1&2&2&8&9&4&1& &  \\
    & &2&5&4&7&8&7&5&6&1&3&5&7&8&7&2&9&3& &  \\
    & & &6&5&6&4&6&7&2&5&2&2&6&3&4&7&4& & &  \\
    & & & &2&3&1&2&3&3&3&2&1&3&2&1&1& & & &  \\
    & & & & & &7&4&4&5&7&3&4&4&7& & & & & &  \\
    & & & & & & & & &3&3&4& & & & & & & & &  \\
    & & & & & & & & & & & & & & & & & & & &  \\
};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

@Zarko 的解决方案tikz可能是最好的。但仅供比较,该nicematrix包确实有命令,它可以通过使用和\chessboardcolors来创建类似的效果。请注意,您必须编译 3 次!cornershvlines

在此处输入图片描述

\documentclass{article}

\usepackage{nicematrix}
\begin{document}

\begingroup\renewcommand{\arraystretch}{1.4}
\begin{NiceTabular}{*{21}{c}}[corners, hvlines]
\CodeBefore
  \chessboardcolors{red!15}{blue!15}
\Body
 & & & & & & & & &4&7&7& & & & & & & & &  \\
 & & & & & &5&4&4&8&3&3&4&6&3& & & & & &  \\
 & & & &1&4&5&1&1&1&4&5&1&7&1&3&5& & & &  \\
 & & &4&9&4&9&6&7&5&5&5&8&7&6&6&8&5& & &  \\
 & &3&7&2&9&8&3&5&6&7&3&9&1&8&7&5&8&5& &  \\
 & &1&4&7&8&4&2&9&2&7&1&1&8&2&2&7&6&3& &  \\
 &7&2&1&8&5&5&3&1&1&3&1&3&3&4&2&8&6&1&3&  \\
 &4&2&6&7&2&5&2&4&2&2&5&4&3&2&8&1&7&7&3&  \\
 &4&1&6&5&1&1&1&9&1&4&3&4&4&3&1&9&8&2&7&  \\
4&3&5&2&3&2&2&3&2&4&2&5&3&5&1&1&3&5&5&3&7 \\
2&7&1&5&1&1&3&1&5&3&3&2&4&2&3&7&7&5&4&2&7 \\
2&5&2&2&6&1&2&4&4&6&3&4&1&2&1&2&6&5&1&8&8 \\
 &4&3&7&5&1&9&3&4&4&5&2&9&4&1&9&5&7&4&8&  \\
 &4&1&6&7&8&3&4&3&4&1&3&1&2&3&2&3&6&2&4&  \\
 &7&3&2&6&1&5&3&9&2&3&2&1&5&7&5&8&9&5&4&  \\
 & &1&6&7&3&4&8&1&1&1&2&1&2&2&8&9&4&1& &  \\
 & &2&5&4&7&8&7&5&6&1&3&5&7&8&7&2&9&3& &  \\
 & & &6&5&6&4&6&7&2&5&2&2&6&3&4&7&4& & &  \\
 & & & &2&3&1&2&3&3&3&2&1&3&2&1&1& & & &  \\
 & & & & & &7&4&4&5&7&3&4&4&7& & & & & &  \\
 & & & & & & & & &3&3&4& & & & & & & & &  
\end{NiceTabular}                 
\endgroup

\end{document}

相关内容