Is there a way to precisely draw this simple diagram? Using tables the outcome is ugly and not as readable as it should be. Or maybe I'm not so good with tables :) Thanks in advance for your help!

Is there a way to precisely draw this simple diagram? Using tables the outcome is ugly and not as readable as it should be. Or maybe I'm not so good with tables :) Thanks in advance for your help!

Please add a TeX code to your next question.
\documentclass{article}
\begin{document}
\[
\begin{array}{ccccc}
1 & 2 & 3 & 4 & \\
\cline{1-4}
\multicolumn{1}{|c|}{a} & \multicolumn{1}{|c|}{b}
& \multicolumn{1}{|c|}{x} &\multicolumn{1}{|c|}{a} & 0\\
\cline{1-4}
& \multicolumn{1}{|c|}{a}
& \multicolumn{1}{|c|}{x} &\multicolumn{1}{|c|}{a} & 1\\
\cline{2-4}
& & \multicolumn{1}{|c|}{x} &\multicolumn{1}{|c|}{b} & 2\\
\cline{3-4}
& & &\multicolumn{1}{|c|}{x} & 3\\
\cline{4-4}
\end{array}
\]
\end{document}
A semantically cleaner solution with blkarray:
\documentclass{article}
\usepackage{blkarray}
\begin{document}
\[ \setlength{\BAextrarowheight}{2pt}
\makeatletter\setlength{\BA@colsep}{5pt}\makeatother
\begin{blockarray}{*{5}{c}}
1 & 2 & 3 & 4 \\
\cline{1-4}%
\begin{block}{*{4}{|c}|c}
a & b & x & a & 0 \\
\BAhhline{----|~}
\end{block}
\begin{block}{c*{3}{|c}|c}
& a & x & a & 1\\
\BAhhline{~|---|~}%
\end{block}
\begin{block}{cc*{2}{|c}|c}
& & x & b & 2 \\
\BAhhline{~~|--|~}%
\end{block}
\begin{block}{*{3}{c}|c|c}
& & & x & 3 \\
\BAhhline{~~~|-|~}%
\end{block}
\end{blockarray} \]
\end{document}
You can use only \hbox, \vbox, \hrule and \vrule primitives:
\newdimen\bxwidth \bxwidth=1.2em
\def\p #1 #2 #3 #4 {\par\hbox{\bp{#1}\bp{#2}\bp{#3}\bp{#4}}}
\def\r #1 {\smallskip\hrule width\dimexpr 4\bxwidth+.4pt\relax}
\def\x #1 #2 #3 #4 #5 {\hbox{\bx{#1}\bx{#2}\bx{#3}\bx{#4}\vrule\bp{#5}}\nointerlineskip}
\def\bp#1{\hbox to\bxwidth{\hss#1\hss}}%
\def\bx#1{\ifx.#1\bp{}%
\else \lower\dimexpr.2\bxwidth+.4pt\vbox{
\bp{\unskip\vrule height.8\bxwidth depth.2\bxwidth\hfil $#1$}\hrule}%
\fi
}
\p 1 2 3 4
\r -------
\x a b x a 0
\x . a x a 1
\x . . x b 2
\x . . . x 3
\bye
This is a version using a matrix of TikZ, with perfect squared boxes.
\documentclass[border=4mm,tikz]{standalone}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\tikzset{square matrix/.style = {
matrix of math nodes,
row sep = -\pgflinewidth,
column sep = -\pgflinewidth,
nodes = {draw,
minimum height = 2em,
text width = 2em,
anchor = center,
align = center,
inner sep = 0pt
},
},
square matrix/.default = 1cm
}
\matrix (m) [square matrix]
{
& & & & \\
a & b & x & a & |[white]|. \\
& a & x & a & |[white]|. \\
& & x & b & |[white]|. \\
& & & b & |[white]|. \\
};
\foreach \i in {2,...,5}
{
\pgfmathtruncatemacro{\y}{\i - 2}
\node at (m-\i-5) {$\y$};
\pgfmathtruncatemacro{\x}{\i - 1}
\node[above, inner sep = 3mm] at (m-2-\x.north) {$\x$};
}
\draw (m-2-5.north west)--(m-5-5.south west);
\end{tikzpicture}
\end{document}
And just for fun... here is an odd solution with skyline puzzle of LogicPuzzle package.
\documentclass[border=4mm]{standalone}
\usepackage{logicpuzzle}
\begin{document}
\skylinesetup{rows=4, columns=4}
\begin{skyline}
\skylineT{1,2,3,4}
\skylineR{3,2,1,0}
\setrow{4}{$a$,$b$,$x$,$a$}
\setrow{3}{{},$a$,$x$,$a$}
\setrow{2}{{},{},$x$,$b$}
\setrow{1}{{},{},{},$x$}
\begin{puzzlebackground}
\fillarea{blue!20}{%
(4,1)--(5,1)--(5,5)--(1,5)--(1,4)--(2,4)--(2,3)--(3,3)--(3,2)--(4,2)--(4,1)}
%\fillarea{white}{(1,1)--(4,1)--(4,2)--(3,2)--(3,3)--(2,3)--(2,4)--(1,4)--(1,1)}
\end{puzzlebackground}
\end{skyline}
\end{document}
The package only works with rectangular grids, so there is no possibility to make the exact figure as the question requires to in this case.
The commented \fillarea{white}{...} line is for coloring and
enframe the other part of the grid. Colors can be changed at will.
minimum height = 2em, text width = 2em, inner sep = 0ptinstructions. She deleted the comments.
– Cragfelt
Dec 31 '17 at 09:19
You can use ytableau:
\documentclass{article}
\usepackage{ytableau}
\begin{document}
\begin{ytableau}
\none[1] & \none[2] & \none[3] & \none[4] \\
a & b & x & a & \none[0] \\
\none & a & x & a & \none[1] \\
\none & \none & x & b & \none[2] \\
\none & \none & \none & x & \none[3]
\end{ytableau}
\end{document}
A tabular solution:
\documentclass{article}
\def\multl#1{\multicolumn{1}{|c}{#1}}
\def\multc#1{\multicolumn{1}{|c}{#1}}
\def\multr#1{\multicolumn{1}{c|}{#1}}
\def\multcr#1{\multicolumn{1}{|c|}{#1}}
\begin{document}
\begin{tabular}{*{5}{c}}
1&2&3&4&\\cline{1-4}
\multl{a}&\multc{b}&\multc{x}&\multcr{a}&0\\cline{1-4}
&&\multl{x}&\multcr{b}&1\\cline{3-4}
&&&\multcr{x}&2\\cline{4-4}
&&&x&3
\end{tabular}
\end{document}
(PS: The line missing before "a" is fixed in the code )