I need to type only half triangular part of a chessboard with different coloring setting and label the rows and columns not by a,b,...;1,2,... but by other letters. More explicitly, I need to type something like the following figure but I couldn't find anyway to do this with any package. Are there any simple way to do this?
Asked
Active
Viewed 260 times
0
-
chessboard is for chess, not for arbitrary collections of square fields. Use tikz for this. – Ulrike Fischer Jul 10 '19 at 10:39
-
See also https://tex.stackexchange.com/questions/168281/how-to-draw-a-chessboard-with-numbers – John Kormylo Jul 10 '19 at 12:49
-
There is a package called tikz based on pgf plots. You would have to read yourself into it, but trust me it is worth it! :D http://www.texample.net/tikz/ – Andreas B. Jul 10 '19 at 10:33
2 Answers
3
You can start from following code:
\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}
Ignasi
- 136,588
0
Just for fun, an alternative that fills the entries programmatically.
\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}


