每个单元格包含 3 个值的收益矩阵

每个单元格包含 3 个值的收益矩阵

您好,我是 Latex 的初学者,需要帮助创建一个收益矩阵,每个单元格中有三个值,按对角线排列。我尝试使用 tikz 包,但没有成功。有人能帮我吗? 在此处输入图片描述

答案1

你当然用 Ti 做Z 但这里不需要它。(编辑:固定间距,非常感谢@Troy!)

\documentclass{article}
\usepackage{array,graphicx,multirow}
\begin{document}
\begin{tabular}{*2{@{\,}r@{\,}}|c|c|}
\multicolumn{2}{c}{}& \multicolumn{2}{c}{Player 1}\\
\multicolumn{2}{c}{}& \multicolumn{1}{l}{A} & \multicolumn{1}{r}{B}\\
\cline{3-4}
\multirow{2}{*}{\rotatebox[origin = r]{90}{Player 2}}
& B &\begin{tabular}{*3{@{}c@{}}}
& & 4\\
& (3) & \\
1 & & 
\end{tabular} & 
\begin{tabular}{*3{@{}c@{}}}
& & 5\\
& (1) & \\
2 & & 
\end{tabular}\\
\cline{3-4}
& A &\begin{tabular}{*3{@{}c@{}}}
& & 6\\
& (5) & \\
1 & & 
\end{tabular} & 
\begin{tabular}{*3{@{}c@{}}}
& & 2\\
& (3) & \\
2 & & 
\end{tabular}\\
\cline{3-4}
\end{tabular}
\end{document}

在此处输入图片描述

只是为了完整性:TiZ 版本。就此目的而言,恕我直言,这有点矫枉过正,但如果您打算添加功能,这可能是更好的选择。

\documentclass{article}
\usepackage{tikz,array}
\usetikzlibrary{matrix,positioning}
\begin{document}
\begin{tikzpicture}
    \matrix (mat) [matrix of nodes,ampersand replacement=\&,nodes={draw,inner sep=4pt},
    column sep=-\pgflinewidth,row sep=-\pgflinewidth]{
       {\begin{tabular}{*3{@{}c@{}}}
& & 4\\
& (3) & \\
1 & & 
\end{tabular}} \& {\begin{tabular}{*3{@{}c@{}}}
& & 5\\
& (1) & \\
2 & & 
\end{tabular}} \\
       {\begin{tabular}{*3{@{}c@{}}}
& & 6\\
& (5) & \\
1 & & 
\end{tabular}} \& {\begin{tabular}{*3{@{}c@{}}}
& & 2\\
& (3) & \\
2 & & 
\end{tabular}} \\
     };
\node [above=1pt of mat-1-1.north west,anchor=south west] (A1) {A};
\node [above=1pt of mat-1-2.north east,anchor=south east] (B1) {B};
\node [left=1pt of mat-1-1,anchor=east] (A2) {A};
\node [left=1pt of mat-2-1,anchor=east] (B2) {B};
\path ([yshift=4pt]A1.north) -- ([yshift=4pt]B1.north) node[midway]{Player 1};
\path ([xshift=-4pt]B2.west) -- ([xshift=-4pt]A2.west) node[midway,rotate=90]{Player 2};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

使用表格和定义新命令来设置主单元格内容:

\documentclass{article}
\usepackage{graphicx}
\usepackage{array,cellspace,multirow}
\setlength\cellspacetoplimit{5pt}
\setlength\cellspacebottomlimit{5pt}
\newcommand\mc[3]{\hfill #1\par          % cell's content at top right
                       (#2)\par          % cell's content on the midle
                         #3\hfill\mbox{}}% cell's content at bottom left

\begin{document}
\begin{tabular}{cc | *{2}{>{\centering\arraybackslash}S{m{12mm}}|}}
\multicolumn{2}{c}{}    &   \multicolumn{2}{c}{Player 1}    \\
\multicolumn{2}{c}{}    &   \multicolumn{1}{c}{A}
                        &   \multicolumn{1}{c}{B}           \\
    \cline{3-4}
\multirow{4}{*}{\rotatebox[origin = c]{90}{Player 2}}
    &   A   &   \mc{4}{3}{1}    &   \mc{5}{1}{2}            \\
    \cline{3-4}
    &   B   &   \mc{6}{5}{1}    &   \mc{2}{3}{2}            \\
    \cline{3-4}
\end{tabular}
\end{document}

在此处输入图片描述

相关内容