長いテキストを含む交通テーブルを作成する方法

長いテキストを含む交通テーブルを作成する方法

この交通表を、表内の文章と表のサイズが合うように改善するのを手伝ってくれる人はいませんか?

ここに画像の説明を入力してください

次のようになります:

希望するテーブル形式

これは輸送テーブルの LaTeX コーディングです。参照。 よろしくお願いします。

\documentclass{article}

\usepackage{array}
\usepackage{multirow}
\usepackage{multicol}

\usepackage{rotating}
\usepackage{tabularx}
\newcommand{\STAB}[1]{\begin{tabular}{@{}c@{}}#1\end{tabular}}

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

\begin{document}
    \begin{table} [h]
        \centering
        \resizebox{\columnwidth}{!}
        {\begin{tabular}{|c|c|C|C|C|c|}
                \hline
                \multicolumn{2}{|c}{\multirow{2}{*}{From $ \backslash $ To}} & \multicolumn{3}{|c|}{Destinations} & \multirow{2}{*}{Supply} \\ \cline{3-5}
                \multicolumn{2}{|c|}{} & Sales Outlet H & Sales Outlet I & Sales Outlet J & \\ \hline
                \multirow{3}{*}{\STAB{\rotatebox[origin=c]{90}{Sources}}} & Warehouse A & \innerbox{}{\$(6,8,10,12)} & \innerbox{}{\$(5,7,9,11)} & \innerbox{}{\$(2,4,6,8)} & (15,20,30,35) \\ \cline{2-6}
                & Warehouse B & \innerbox{}{\$(3,5,7,9)} & \innerbox{}{\$(5,7,9,11)} & \innerbox{}{\$(1,3,5,7)} & (25,30,40,45) \\ \cline{2-6}
                & Warehouse C & \innerbox{}{\$(4,6,8,10)} & \innerbox{}{\$(3,5,7,9)} & \innerbox{}{\$(6,8,10,12)} & (30,35,45,50) \\ \hline
                \multicolumn{2}{|c|}{Demand} & (15,25,35,45) & (10,20,30,40) & (30,40,50,60) & \\ \hline
        \end{tabular}}
    \end{table}
\end{document}

答え1

画像に示されているように、すべての内部ボックスの幅を同じにしたいのだと思います。ただし、これを LaTeX で行うのは非常に困難です (不可能ではありませんが)。2 回実行する必要があります。そのため、簡単な方法を選択しました。\innerboxwidthこれには長さがあります。私のソリューションで行ったように、最も広いエントリの幅に初期化する必要があります。

ちなみに、中央揃えになるように\multirowforを 5 に変更しました。Sources

\documentclass{article}

\usepackage{array}
\usepackage{multirow}
\usepackage{multicol}

\usepackage{rotating}
\usepackage{tabularx}
\usepackage{array}
\newcommand{\STAB}[1]{\begin{tabular}{@{}c@{}}#1\end{tabular}}

\newcolumntype{C}{@{}c@{}}
\newcommand{\bottombox}[1]{\makebox[1em][r]{#1}\hspace*{\tabcolsep}\hspace*{1em}}%
\newlength{\innerboxwidth}
\settowidth{\innerboxwidth}{\$(6,8,10,12)}% widest entry
\newcommand{\innerbox}[2]{%
    \begin{tabular}[c]{c|>{\centering\arraybackslash}p{\innerboxwidth}}
        \rule{1em}{0pt} & {#2} \\\cline{2-2}
        \multicolumn{2}{r}{{#1}\hspace*{1\tabcolsep}\hspace*{1em}\rule[-1ex]{0pt}{1ex}}
\end{tabular}}
\renewcommand{\arraystretch}{1}

\begin{document}
    \begin{table} [h]
        \centering
        \resizebox{\columnwidth}{!}
        {\begin{tabular}{|c|c|C|C|C|c|}
                \hline
                \multicolumn{2}{|c}{\multirow{2}{*}{From $ \backslash $ To}} & \multicolumn{3}{|c|}{Destinations} & \multirow{2}{*}{Supply} \\ \cline{3-5}
                \multicolumn{2}{|c|}{} & Sales Outlet H & Sales Outlet I & Sales Outlet J & \\ \hline
                \multirow{5}{*}{\STAB{\rotatebox[origin=c]{90}{Sources}}} & Warehouse A & \innerbox{}{\$(6,8,10,12)} & \innerbox{}{\$(5,7,9,11)} & \innerbox{}{\$(2,4,6,8)} & (15,20,30,35) \\ \cline{2-6}
                & Warehouse B & \innerbox{}{\$(3,5,7,9)} & \innerbox{}{\$(5,7,9,11)} & \innerbox{}{\$(1,3,5,7)} & (25,30,40,45) \\ \cline{2-6}
                & Warehouse C & \innerbox{}{\$(4,6,8,10)} & \innerbox{}{\$(3,5,7,9)} & \innerbox{}{\$(6,8,10,12)} & (30,35,45,50) \\ \hline
                \multicolumn{2}{|c|}{Demand} & (15,25,35,45) & (10,20,30,40) & (30,40,50,60) & \\ \hline
        \end{tabular}}
    \end{table}
\end{document}

ここに画像の説明を入力してください

関連情報