不规则棋盘和标签

不规则棋盘和标签

我只需要输入棋盘的半个三角形部分,并使用不同的颜色设置,并用其他字母标记行和列,而不是 a、b、...;1、2、...。更明确地说,我需要输入类似下图的内容,但我找不到任何包来执行此操作。有没有简单的方法可以做到这一点?

在此处输入图片描述

答案1

您可以从以下代码开始:

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{matrix, positioning}

\begin{document}
\begin{tikzpicture}
\matrix (A) [matrix of nodes,
    nodes={draw, fill, minimum size=9mm}]
    {~&~&~&~&|[fill=white]|~&|[fill=white]|~&|[fill=white]|~\\
     &~&~&~&|[fill=white]|~&|[fill=white]|~&|[fill=white]|~\\
     &&~&~&|[fill=white]|~&|[fill=white]|~&|[fill=white]|~\\
     &&&~&~&~&~\\
     &&&&~&~&~\\
     &&&&&~&~\\
     &&&&&&~\\};
    \foreach \i [count=\ni from 4, count=\nj from 2] in {1,...,7}{ 
        \node[right=1mm of A-\i-7.east]{$a_{1\nj}$};
        \node[above=1mm of A-1-\i.north]{$a_{\ni(11)}$};
    }
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

只是为了好玩,一种以编程方式填充条目的替代方法。

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix[matrix of nodes,nodes in empty cells,column sep=-\pgflinewidth,row
sep=-3*\pgflinewidth,nodes={align=center,minimum width=4em,minimum height=4em,
/utils/exec=\ifnum\the\pgfmatrixcurrentcolumn<8
\ifnum\the\pgfmatrixcurrentrow>1 
 \ifnum\the\numexpr\pgfmatrixcurrentcolumn+1\relax>\the\numexpr\pgfmatrixcurrentrow-1\relax
  \ifnum\the\pgfmatrixcurrentcolumn>4
   \ifnum\the\pgfmatrixcurrentrow<5
    \tikzset{draw,fill=white}
   \else
    \tikzset{draw,fill}
   \fi
   \else
   \tikzset{draw,fill}
  \fi 
 \else
 \fi
\fi
\fi,
execute at begin node={\ifnum\the\pgfmatrixcurrentrow=1%
\ifnum\the\pgfmatrixcurrentcolumn<8% 
$a_{\the\numexpr\pgfmatrixcurrentcolumn+3\relax(11)}$%
\fi%
\else%
\ifnum\the\pgfmatrixcurrentcolumn=8% 
$a_{1\the\pgfmatrixcurrentrow}$%
\fi%
\fi%
}}] (mat)
 {& & & & & & &\\
 & & & & & & &\\
 & & & & & & &\\
 & & & & & & &\\
 & & & & & & &\\
 & & & & & & &\\
 & & & & & & &\\
 & & & & & & &\\
 };
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容