How to make a transportation tableau

I am trying to make a transportation tableau in LaTeX. The tableau I wanted looks like the one below.

-
Welcome to TeX.sx! On this site, a question should typically revolve around an abstract issue (e.g. "How do I get a double horizontal line in a table?") rather than a concrete application (e.g. "How do I make this table?"). Questions that look like "Please do this complicated thing for me" tend to get closed because they are "too localized". Please try to make your question clear and simple by giving a minimal working example (MWE): you'll stand a greater chance of getting help. – Kurt Nov 21 '12 at 18:31
@Kurt has given some good general advice, but in this case the question (what you want) is crystal clear; what is not clear is how much help you need to solve your problem. This is usually abbreviated as "what have you tried?". By including a partial solution, you participate in solving your problem and show us where you need us to take over. – alexis Nov 21 '12 at 18:47
I know how to create a table but I would like some hint on how to create one like this. I have googled on this problem. But there is nothing. – user729470 Nov 21 '12 at 19:18
Are you looking for a diagonal line in a table cell? – Stephen Nov 21 '12 at 19:49

It looks like this can be done with TikZ. You could

• build matrix of nodes for all the entries. Here I mean the small entries positioned in a matrix, not the big cells.

• Each cell in a matrix can be refered to for drawing lines. So, even if there's not yet an automatic way, you can draw all lines in blue between the nodes yourself, anchoring as desired.

• For cleaner code and resusability, define styles, such as node styles (italic font for some numbers, bold font for other entries, framed entries, text alignment in nodes).

-

It seems there's a partial solution given at Diagonal lines in table cell. The example there uses TikZ to produce the diagonal. But, I would find building the whole table in TikZ a bit too tedious. My solution would be to nest tabular environments and define a new column type (to avoid ugly breaks in the lines). Here's my code---hope it's not too clunky. I'm omitting the diagonal: for that see the link above.

\documentclass{article}
\usepackage{array}
\newcolumntype{C}{@{}c@{}}
\newcommand{\bottombox}[1]{\makebox[2em][r]{#1}\hspace*{\tabcolsep}\hspace*{2em}}%
\newcommand{\innerbox}[2]{%
\begin{tabular}[b]{c|c}
\rule{2em}{0pt}\rule[-2ex]{0pt}{5ex} & \makebox[2em]{#2} \\\cline{2-2}
\multicolumn{2}{r}{{#1}\hspace*{1.5\tabcolsep}\hspace*{2em}\rule[-2ex]{0pt}{5ex}}
\end{tabular}}
\renewcommand{\arraystretch}{1.25}
\begin{document}

\begin{tabular}{c|C|C|C|r}\hline
& A                 & B                 & C                 & Supply  \\\hline
1      & \innerbox{}{12}   & \innerbox{}{10}   & \innerbox{600}{6} &   600   \\\hline
2      & \innerbox{400}{4} & \innerbox{}{15}   & \innerbox{}{3}    &   400   \\\hline
3      & \innerbox{300}{9} & \innerbox{}{7}    & \innerbox{}{M}    &   300   \\\hline
4      & \innerbox{}{11}   & \innerbox{500}{8} & \innerbox{300}{6} &   800   \\\hline
Dummy  & \innerbox{200}{0} & \innerbox{}{0}    & \innerbox{}{0}    &   200   \\\hline
Demand & \bottombox{900}   & \bottombox{500}   & \bottombox{900}   & 2,300   \\\hline
\end{tabular}

\end{document}

-
Precisely, this is what I was looking for. Excellent. Thanks a trillion Ellett. God bless. – user729470 Nov 22 '12 at 8:31
@user729470 As it helped, you could upvote the answer of A.Ellet and accept it. – Stefan Kottwitz Nov 22 '12 at 10:10
I have tried to upvote A. Ellett answer but it is refusing.. – user729470 Nov 22 '12 at 10:18

I have added the part for diagonal (To/From). Thanks Ellett

  \documentclass{article}
\usepackage{array}
\usepackage{tikz}
\newcommand\diag[4]{%
\multicolumn{1}{p{#2}|}{\hskip-\tabcolsep
$\vcenter{\begin{tikzpicture}[baseline=0,anchor=south west,inner sep=#1] \path[use as bounding box] (0,0) rectangle (#2+2\tabcolsep,\baselineskip); \node[minimum width={#2+2\tabcolsep},minimum height=\baselineskip+\extrarowheight] (box) {}; \draw (box.north west) -- (box.south east); \node[anchor=south west] at (box.south west) {#3}; \node[anchor=north east] at (box.north east) {#4}; \end{tikzpicture}}$\hskip-\tabcolsep}}

\newcolumntype{C}{@{}c@{}}
\newcommand{\bottombox}[1]{\makebox[2em][r]{#1}\hspace*{\tabcolsep}\hspace*{2em}}%
\newcommand{\innerbox}[2]{%
\begin{tabular}[b]{c|c}
\rule{2em}{0pt}\rule[-2ex]{0pt}{5ex} & \makebox[2em]{#2} \\\cline{2-2}
\multicolumn{2}{r}{{#1}\hspace*{1.5\tabcolsep}\hspace*{2em}\rule[-2ex]{0pt}{5ex}}
\end{tabular}}
\renewcommand{\arraystretch}{1.25}
\begin{document}

\begin{tabular}{c|C|C|C|r}\hline
\diag{.1em}{1.5cm}{From}{To}& A         & B     & C         & Supply  \\\hline
1      & \innerbox{}{12}   & \innerbox{}{10}   & \innerbox{600}{6} &   600   \\\hline
2      & \innerbox{400}{4} & \innerbox{}{15}   & \innerbox{}{3}    &   400   \\\hline
3      & \innerbox{300}{9} & \innerbox{}{7}    & \innerbox{}{M}    &   300   \\\hline
4      & \innerbox{}{11}   & \innerbox{500}{8} & \innerbox{300}{6} &   800   \\\hline
Dummy  & \innerbox{200}{0} & \innerbox{}{0}    & \innerbox{}{0}    &   200   \\\hline
Demand & \bottombox{900}   & \bottombox{500}   & \bottombox{900}   & 2,300   \\\hline
\end{tabular}

\end{document}

-