Creating a triangular table
TikZ has a rotate
option. Here is an example:
% without rotate
\begin{tikzpicture}[y={(0, -1)}]
\path (0.5, -0.5) node{1} ++(1, 0) node{2};
\path (-0.5, 0.5) node{1} ++(0, 1) node{2};
\draw (0, 2) grid (2, 0);
\node at (0.5, 0.5) {$12.34$};
\node at (2.5, 2.5) {$A_1$};
\end{tikzpicture}
% with rotate
\begin{tikzpicture}[y={(0, -1)}, rotate=-45]
\path (0.5, -0.5) node{1} ++(1, 0) node{2};
\path (-0.5, 0.5) node{1} ++(0, 1) node{2};
\draw (0, 2) grid (2, 0);
\node at (0.5, 0.5) {$12.34$};
\node at (2.5, 2.5) {$A_1$};
\end{tikzpicture}
And the results:
Update:
\begin{tikzpicture}[y={(0, -1)}, rotate=-45]
\path (0.5, -0.5) node{1} ++(1, 0) node{2};
\path (-0.5, 0.5) node{1} ++(0, 1) node{2};
\foreach \y in {0,...,2} {
\foreach \x in {0,...,\y} {
\draw (\x, \y - \x) rectangle +(1, 1);
}
}
\node at (0.5, 0.5) {$12.34$};
\node at (2.5, 2.5) {$A_1$};
\end{tikzpicture}
Result:
The diamond
shape is only there for drawing and filling, the text is actually only a label (which is actually a node too) to the diamond node.
This works best only with an angle of 45.
One could also solve this with a custom coordinate system (x going ↗, y going ↘) instead of rotation, the squares/diamonds could have been drawn also with a rectangular path.
The size of the shape is manually set to
minimum size=1.414cm+0.4\pgflinewidth
The co-efficient of \pgflinewidth
is found empirical and is chosen so that the lines overdraw eachother, as a grid
would do that.
Code
\documentclass[tikz]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}[
rotate=-45,
every label/.append style={text depth=+0pt},
label position=center,
every cell/.style={fill=gray!25},
column 3/.style={fill=red!25},
row 5/.style={fill=green!25},
cell 2-2/.style={fill=gray},
cell 3-2/.style={fill=gray!50},
]
\foreach \jRow[count=\jCount from 1, remember=\mCount] in {%
0,%
{15750,0},%
{7875,2625,0},%
{9375,4375,750,0},%
{11875,7125,2500,1000,0},%
{15125,10500,5375,3500,5000,0}%
} {
\foreach \mCell[count=\mCount from 1, remember=\mCount] in \jRow {
\node[
diamond,
minimum size=1.414cm+0.4\pgflinewidth,
draw,
every cell/.try,
row \jCount/.try,
column \mCount/.try,
cell \jCount-\mCount/.try,
label={\pgfmathprintnumber{\mCell}},
alias=@lastnode,
alias=@lastrow-\mCount
] at (\mCount-.5,\jCount-.5) {};
\ifnum\mCount=1
\path [late options={name=@lastnode, label=above left:$\jCount$}];
\fi
}
\path [late options={name=@lastnode, label=below:$A_\jCount$}];
}
\foreach \mCountExtra in {1,...,\mCount}
\path [late options={name=@lastrow-\mCountExtra, label=above right:$\mCountExtra$}];
\end{tikzpicture}
\end{document}