收益矩阵太宽

收益矩阵太宽

我正在尝试使用 LaTeX 创建一个 3X8 的收益矩阵,并且使用了以下命令:

\documentclass{article}

\usepackage{sgame}

\begin{document}

\begin{figure}[htb]\hspace*{\fill}
\begin{game}{3}{8}[Player~1][Player~2][\(A\)]
      & \(Veto ZXY\) & \(Veto ZXX\) & \(Veto ZZY\)& \(Veto ZZX\)& \(Veto YXY\) & \(Veto YXX\) & \(Veto YZY\)& \(Veto YZX\)\\
\(Veto X\) &\(2,2\) &\(2,2\) &\(2,2\)& \(2,2\) &\(1,3\) &\(1,3\) &\(1,3\)& \(1,3\)\\
\(Veto Y\) &\(1,3\) &\(1,3\) &\(3,1\)& \(3,1\)&\(1,3\) &\(1,3\) &\(3,1\)& \(3,1\)\\
\(Veto Z\) &\(3,1\) &\(2,2\) &\(3,1\)& \(2,2\) &\(3,1\) &\(2,2\) &\(3,1\)& \(2,2\)
\end{game}\hspace*{\fill}
\caption[]{}
\end{figure}

\end{document}

您可以想象,矩阵太宽,因此我收到以下消息:

Overfull \hbox (121.53635pt too wide) in paragraph at lines 164--171

谁能帮我?

答案1

看来该sgame包不允许设置列宽。

您可以使用普通表格,这里有一个示例tabularray

\documentclass{article}
\usepackage{sgame}
\usepackage{graphicx}
\usepackage{tabularray}

\begin{document}
\begin{figure}[htb]\centering\small
    \begin{tblr}{colspec={cl*{8}{Q[m,c,2.6em]}},
            hline{3-Y}={3-Z}{solid}, 
            vline{3-Z}={3-Y}{solid},
            column{1}={rightsep=0pt,leftsep=0pt},
            row{3-Y}={abovesep=2pt,belowsep=0pt},
            row{Z}={abovesep=5pt},
            column{3-Z}={mode=math},
            row{1-2}={mode=text}
            }
        &&\SetCell[c={8}]{m} Player~2\\
        && Veto \(ZXY\) & Veto \(ZXX\) & Veto \(ZZY\)& Veto \(ZZX\)& Veto \(YXY\) & Veto \(YXX\) & Veto \(YZY\)& Veto \(YZX\)\\
        \SetCell[r={3}]{m}\rotatebox{90}{Player~1}&Veto \(X\) &2,2 &2,2 &2,2& 2,2 &1,3 &1,3 &1,3& 1,3\\
        &Veto \(Y\) &1,3 &1,3&3,1& 3,1&1,3 &1,3 &3,1& 3,1\\
        &Veto \(Z\) &3,1 &2,2 &3,1&2,2 &3,1 &2,2 &3,1& 2,2\\
        &&\SetCell[c={8}]{m} A
    \end{tblr}  
    \caption{A caption}
\end{figure}
\end{document}

在此处输入图片描述

答案2

存在问题sgame,因为它与标准array包不兼容。

您可以使用我在https://tex.stackexchange.com/a/512953/4427

\documentclass{article}
%\usepackage{xparse} % not needed with a recent LaTeX release
\usepackage{hhline,array,multirow}

\newcommand{\splitcell}[1]{\begin{tabular}{@{}c@{}}#1\end{tabular}}

\newcommand\doubleactivetilde{~~} % hhline wants ~ to mean 'column with no line'

\ExplSyntaxOn

\seq_new:N \l_cfr_game_body_seq
\seq_new:N \l_cfr_game_first_seq
\tl_new:N \l_cfr_game_first_tl
\cs_generate_variant:Nn \seq_set_split:Nnn { NnV }

\cs_new_protected:Nn \__cfr_game_first:n
 {
  & \multicolumn{1}{c}{#1}
 }

\NewDocumentEnvironment{game}{mmooob}
 {% #1 = number of rows, #2 = number of columns (besides the label column)
  % #3 = left label, #4 = top label, #5 = bottom label
  % #6 = body

  % split the body at \\
  \seq_set_split:Nnn \l_cfr_game_body_seq { \\ } { #6 }
  % in case there's a trailing \\
  \seq_pop_right:NN \l_cfr_game_body_seq \l_tmpa_tl
  \tl_if_empty:NF \l_tmpa_tl { \seq_put_right:NV \l_cfr_game_body_seq \l_tmpa_tl }
  %
  \seq_pop_left:NN \l_cfr_game_body_seq \l_cfr_game_first_tl
  \seq_set_split:NnV \l_cfr_game_first_seq { & } \l_cfr_game_first_tl
  % discard the first (empty) item
  \seq_pop_left:NN \l_cfr_game_first_seq \l_tmpa_tl
  \begin{tabular}{@{}c@{}r*{#2}{|c}|}
  % top label
  \IfValueT{#4}{\multicolumn{2}{@{}c}{} & \multicolumn{#2}{c}{#4} \\}
  % first row
  \multicolumn{2}{c}{} \seq_map_function:NN \l_cfr_game_first_seq \__cfr_game_first:n \\
  \exp_args:No \hhline{\doubleactivetilde*{#2}{|-}|}
  \IfValueTF{#3}{\multirow{#1}{*}{#3\quad}}{\multicolumn{1}{@{}c@{}}{}}
  & \seq_use:Nn \l_cfr_game_body_seq
   { \\ \exp_args:No \hhline{\doubleactivetilde*{#2}{|-}|} & } \\
  \exp_args:No \hhline{\doubleactivetilde*{#2}{|-}|}
  \IfValueT{#5}
   {
    \multicolumn{2}{c}{\rule{0pt}{1.25\normalbaselineskip}} &
    \multicolumn{#2}{c}{\makebox[0pt]{#5}} \\
   }
  \end{tabular}
}{}

\ExplSyntaxOff


\begin{document}

\begin{figure}[htb]
\centering

\begin{game}{3}{8}[Player~1][Player~2][Description]
& \splitcell{Veto \\ ZXY}
& \splitcell{Veto \\ ZXX}
& \splitcell{Veto \\ ZZY}
& \splitcell{Veto \\ ZZX}
& \splitcell{Veto \\ YXY}
& \splitcell{Veto \\ YXX}
& \splitcell{Veto \\ YZY}
& \splitcell{Veto \\ YZX}\\
Veto X &2,2 &2,2 &2,2& 2,2 &1,3 &1,3 &1,3& 1,3\\
Veto Y &1,3 &1,3 &3,1& 3,1&1,3 &1,3 &3,1& 3,1\\
Veto Z &3,1 &2,2 &3,1& 2,2 &3,1 &2,2 &3,1& 2,2
\end{game}

\caption{The global caption to the matrix}

\end{figure}

\end{document}

在此处输入图片描述

答案3

与。{NiceTabular}nicematrix

\documentclass{article}
\usepackage{nicematrix}

\begin{document}
\begin{figure}[htb]
\centering
\setlength{\tabcolsep}{4pt}
\begin{NiceTabular}{*{10}{c}}[cell-space-limits=3pt]
    &       & \Block{1-*}{Player 2} \\
    &       & Veto  & Veto  & Veto  & Veto  & Veto  & Veto  & Veto  & Veto  \\ 
    &       & ZXY   & ZXX   & ZZY   & ZZX   & YXY   & YXX   & YZY   & YZX   \\
\Block{3-1}<\rotate>{Player 1}
    &Veto X & \Block[hvlines]{3-*}{}
              2,2   & 2,2   & 2,2   & 2,2   & 1,3   & 1,3   & 1,3   & 1,3   \\  
    &Veto Y & 1,3   & 1,3   & 3,1   & 3,1   & 1,3   & 1,3   & 3,1   & 3,1   \\
    &Veto Z & 3,1   & 2,2   & 3,1   & 2,2   & 3,1   & 2,2   & 3,1   & 2,2   \\
    &       &  \Block{1-*}{A} \\
\end{NiceTabular}
\caption{A caption}
\end{figure}
\end{document}

您需要多次编译(因为nicematrix在后台使用 PGF/Tikz 节点)。

上述代码的输出

答案4

如表所示,与@CarLaTeX 答案类似,但代码略短:

\documentclass{article}
\usepackage{tabularray}

\begin{document}
    \begin{figure}[htb]
    \centering
\begin{tblr}{cells = c,
             hline{4-Y} = {3-Z}{solid}, vline{3-Z} = {4-Y}{solid},
             colsep=4pt,
             row{2}={rowsep=-1pt},
            }
    &       &   \SetCell[c=8]{c} Player 2 
                    &       &       &       &       &       &       &       \\
    &       & Veto  & Veto  & Veto  & Veto  & Veto  & Veto  & Veto  & Veto  \\ 
    &       & ZXY   & ZXX   & ZZY   & ZZX   & YXY   & YXX   & YZY   & YZX   \\
\SetCell[r=3]{c}    Player 1 
    &Veto X & 2,2   & 2,2   & 2,2   & 2,2   & 1,3   & 1,3   & 1,3   & 1,3   \\  
    &Veto Y & 1,3   & 1,3   & 3,1   & 3,1   & 1,3   & 1,3   & 3,1   & 3,1   \\
    &Veto Z & 3,1   & 2,2   & 3,1   & 2,2   & 3,1   & 2,2   & 3,1   & 2,2   \\
    &       &   \SetCell[c=8]{c}    A
                    &       &       &       &       &       &       &       \\
    \end{tblr}
\caption{A caption}
    \end{figure}
\end{document}

在此处输入图片描述

相关内容