2

I want to create table cell like that for transporting problem

enter image description here

I can create like this, but not with three element in cell

    \documentclass[12pt,a4paper]{scrartcl}
    \usepackage[utf8]{inputenc}
    \usepackage[english,ukrainian]{babel}
    \usepackage{indentfirst}
    \usepackage{misccorr}
    \usepackage{graphicx}
    \usepackage{amsmath}
    \usepackage{multirow}
    \usepackage{array}

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

    \begin{document}
        \begin{center} \begin{tabular}{|c|c|c|c|c|c|c|}
   \hline
   & $B_1$ & $B_2$ & $B_3$ & $B_4$ & $B_5$ & Запаси \\
   \hline
   $A_1$ & \innerbox{11}{17} & \innerbox{4}{20} & \innerbox{}{29} & \innerbox{}{26} & \innerbox{}{25} & 15   \\
   \hline
   $A_2$ & \innerbox{}{3} & \innerbox{7}{4} & \innerbox{8}{5} & \innerbox{}{15} & \innerbox{}{24} & 15   \\
    \hline
   $A_3$ & \innerbox{}{19} & \innerbox{}{2} & \innerbox{3}{22} & \innerbox{11}{4} & \innerbox{1}{13} & 15   \\
    \hline
   $A_4$ & \innerbox{}{20} & \innerbox{}{27} & \innerbox{}{1} & \innerbox{}{17} & \innerbox{15}{19} & 15   \\
   \hline
   Потреби & 11 & 11 & 11 & 11 & 16 & 60 \\
    \hline
   \end{tabular}
   \end{center}
    \end{document}

enter image description here

  • I want to have cell like in the picture @Schweinebacke – Stepan Vanzuriak Nov 9 '17 at 8:51
3

What about something like this?

\documentclass{scrartcl}
\usepackage{makecell}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\begin{document}

\begin{tabular}{c|P{1.5cm}|P{1.5cm}|P{1.5cm}|P{1.5cm}|P{1.5cm}}

 & $B_1$& $B_2$ & $B_3$ & $B_4$ & $B_5$\\
 $A_1$ & \makecell[r]{1} & \makecell[r]{4} & \makecell[r]{2} & \makecell[r]{5} & \makecell[r]{M}\\
  & 30 & 0 & 20 & 10 & 0\\
  & \makecell[l]{30} & \makecell[l]{10} & \makecell[l]{20} & \makecell[l]{10} & \makecell[l]{$\infty$}\\
\end{tabular}

\end{document}

enter image description here

In this short example I have used the makecell package to individually left or right align the contents of a cell. Additionally, I have defined a new, centered column type P.

2

Fill in the missing data:

\documentclass{article}

\newcommand{\threecell}[3]{% #1 = top, #2 = middle, #3 = bottom
  \renewcommand{\arraystretch}{1.2}%
  \begin{tabular}[t]{@{}c@{}}
  \makebox[2em][r]{#1}\\
  \makebox[2em][c]{#2}\\
  \makebox[2em][l]{#3}
  \end{tabular}
}

\begin{document}

\begin{tabular}{|*{6}{c|}}
\hline
& $B_1$ & $B_2$ & $B_3$ & $B_4$ & $B_5$ \\
\hline
\makebox[2em]{$A_1$} &
  \threecell{1}{30}{30} &
  \threecell{4}{0}{10} &
  \threecell{2}{20}{20} &
  \threecell{5}{10}{10} &
  \threecell{M}{0}{$\infty$} \\
\hline
\makebox[2em]{$A_2$} &
  \threecell{2}{0}{10} &
  \threecell{1}{10}{10} &
  \threecell{4}{10}{10} &
  \threecell{1}{10}{20} &
  \threecell{M}{0}{$\infty$} \\
\hline
\end{tabular}

\end{document}

enter image description here

2

Here is an alternative solution I came up with:

\documentclass{scrartcl}

\newcommand{\diagarraythree}[3]{$\begin{array}{ccc}  & & #1 \\%
                                                     & #2 & \\%
                                                     #3 & &  \end{array}$}

\begin{document}
\begin{tabular}{c|c|c|c|c|c}
 & $B_1$& $B_2$ & $B_3$ & $B_4$ & $B_5$\\
  $A_1$ & \diagarraythree{1}{30}{30} & \diagarraythree{4}{0}{10} & \diagarraythree{2}{20}{20} & \diagarraythree{5}{10}{10} & \diagarraythree{M}{0}{\infty} \\
\end{tabular}  
\end{document}

enter image description here

In this solution I used the array environment to position the numbers. In order to simplify the code, I defined the new command diagarraythree that takes the three numbers as arguments and prints them in the diagonal of a 3x3 matrix as shown in the image.

Benefits of this approach:

  • less typing
  • no guessing of an appropriate width for the table cells needed
  • extendable to aligning four or more entries

The code is easily adaptable for an analogous alignment of four or more entries as shown in the following example:

\documentclass{scrartcl}

\newcommand{\diagarrayfour}[4]{$\begin{array}{cccc} & & & #1 \\%
                                                    & & #2 & \\%
                                                    & #3 & & \\
                                                    #4 & & &  \end{array}$}

\begin{document}
\begin{tabular}{c|c|c}
 & $B_1$& $B_2$ \\
  $A_1$ & \diagarrayfour{1}{30}{30}{5} & \diagarrayfour{4}{0}{10}{5}  \\
\end{tabular}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.