Diagonally divided table cell

A simple solution is to use the slashbox package

\documentclass{article}
\usepackage{slashbox}
\begin{document}

\begin{tabular}{c|cc}
 \backslashbox{n}{k} & 0 & 1\\\hline
0 & 1 & 2 \\
\end{tabular}


\end{document}

alt text

If you want to connect certain cells within the table with arrows and so an, it might be easier to use tikz. Here is a somehow evil hack to get a slashbox in a matrix of nodes. I am sure this can be done much better by someone else

\documentclass{article}
\usepackage{slashbox}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}

%\begin{tabular}{c|cc}
 %\backslashbox{n}{k} & 0 & 1\\\hline
%0 & 1 & 2 \\
%\end{tabular}

\begin{tikzpicture}
 \matrix (mymatrix) [matrix of nodes,
            nodes in empty cells,
%text depth=.5ex,
text height=1.5ex,
text width=1.5ex
            ]
{
\begin{scope} \tikz\node[overlay] at (-.8ex,-0.4ex){\footnotesize n};\tikz\node[overlay] at (1ex,0.5ex){\footnotesize k}; \end{scope} & 2 & 3 & 8\\\hline
4 & |[fill=blue!10]|5 & 6 & 4\\
7 & 8 & 9 & 0\\
10 & 11 & 12 & |[fill=blue!10]|1\\
};
%vertical and diagonal line
\draw (mymatrix-1-2.north west) -- (mymatrix-4-2.south west);
\draw (mymatrix-1-1.north west) -- (mymatrix-1-1.south east);%n k diagonal line

%connection between nodes
\draw[->] (mymatrix-2-2) to [bend right=25] (mymatrix-4-4.north west);

\end{tikzpicture}


\end{document}

alt text


\input eplain
\vbox{\offinterlineskip
\halign{\tabskip1em
  $\phantom{\Big)}#$&\vrule#&&\hfil$#$\hfil\cr
  \sarrowlength=1.5em
  \hidewidth\matrix{\sline(1,-1)\lft{n}\rt{k}}\hidewidth
    && 0 & 1 & 2 & 3 & 4 & 5 & 6 & \cdots \cr
  \noalign{\hrule}
  0 && 0 & 1 & 0 & 0 & 0 & 0 & 0 & \vdots \cr
  1 && 1 & 0 & 0 & 0 & 0 & 0 & 0 & \cr
  2 && 1 & 2 & 1 & 0 & 0 & 0 & 0 \cr
  3 && 1 & 3 & 3 & 1 & 0 & 0 & 0 \cr
  4 && 1 & 4 & 6 & 4 & 1 & 0 & 0 \cr
  5 && 1 & 5 & 10 & 10 & 5 & 1 & 0 \cr
  \vdots && \cdots \cr
}}\bye


It could use some better spacing, but the idea is there.

Tags:

Tables