# Creating a triangular table

Is there a way to create something that looks like this?

I have looked at the \rotatebox command, but that will not get the same "jagged" edges on the bottom, and looked at How to draw a diagonally-split grid with TikZ? which seems applicable (especially in conjunction with the \rotatebox).

I was able to make this:

With code adapted from the link, but I have no idea how to customize it.

\documentclass[12pt]{article}
\usepackage[english]{babel}
\usepackage{amsfonts}
\usepackage{tikz}
\usepackage{rotating}
\usetikzlibrary{calc,decorations.shapes}
\tikzset{
decorate with/.style args={#1 separated by #2}{
fill,
decorate,decoration={shape backgrounds,shape=#1,shape size=1.5mm,
shape sep={#2, between borders}}
}
}

\pgfkeys{/tikz/.cd,
}

\begin{document}

\usetikzlibrary{calc,decorations.shapes}
\rotatebox{315}{\begin{tikzpicture}[x=0.5025cm,y=0.5025cm,line cap=round]
\node [draw, minimum size=0.5cm,outer sep=0pt,inner sep=0pt] (u-\xi\yi) at (\xi,-\yi) {};
}
}
\end{tikzpicture}
}
\end{document}

-
Please add a minimal working example (MWE) compilable code, starting with \documentclass{...} and ending with \end{document}. –  texenthusiast Apr 26 '13 at 3:04
@texenthusiast Done –  soandos Apr 26 '13 at 3:08
@soandos I think, here you're better off with the diamond shape or a matrix-like approach. How’d you want to have your input? –  Qrrbrbirlbel Apr 26 '13 at 3:08
@Qrrbrbirlbel, I was in the middle and accidently clicked saved the intermediate. –  soandos Apr 26 '13 at 3:09

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}


## Output

-

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:

-
As new user without image posting privileges simply include the image as normal and remove the ! in front of it to turn it into a link. A moderator or another user with edit privileges can then reinsert the ! to turn it into an image again. –  texenthusiast Apr 26 '13 at 3:21
How can I remove the bottom two lines, and then put the bottom labels at the bottom of the other cells? –  soandos Apr 26 '13 at 3:24
@soandos: Just replace the line of grid with your line drawing code (a \foreach is required). –  SaltyEgg Apr 26 '13 at 3:27
mind editing your answer to explain? –  soandos Apr 26 '13 at 3:32
OK, wait a minute –  SaltyEgg Apr 26 '13 at 3:37