我尝试为博弈论建立一个收益矩阵,我使用了以下代码:
\documentclass{article}
\usepackage{multirow,array}
\begin{document}
\begin{table}
\setlength{\extrarowheight}{2pt}
\begin{tabular}{cc|c|c|}
& \multicolumn{1}{c}{} & \multicolumn{2}{c}{Player $Y$}\\
& \multicolumn{1}{c}{} & \multicolumn{1}{c}{$A$} & \multicolumn{1}{c}{$B$} \\\cline{3-4}
\multirow{2}*{Player $X$} & $A$ & $(x,y)$ & $(x,y)$ \\\cline{3-4}
& $B$ & $(x,y)$ & $(x,y)$ \\\cline{3-4}
\end{tabular}
\end{table}
\end{document}
并且应该有以下结果:
但是我有一个问题,我的X
和y
真的很长,我想把它们放在不同的行,比如(x,\\y)
,但这对我来说很困难,我试过谷歌,他们说使用:
\newcommand{\tabincell}[2]{\begin{tabular}{@{}#1@{}}#2\end{tabular}}
但在那之后,它一直告诉我“缺少$插入”错误,并且“x”和“y”中的某些字母处于文本模式而不是数学模式,即使我$
在它们周围插入了这些字母。
答案1
像这样?
对于这个包来说变得mathtools
方便:
\documentclass{article}
\usepackage{mathtools}
\usepackage{makecell, multirow}
\setcellgapes{3pt}
\begin{document}
\begin{table}
\makegapedcells
\begin{tabular}{cc|c|c|}
& \multicolumn{1}{c}{} & \multicolumn{2}{c}{Player $Y$}\\
& \multicolumn{1}{c}{} & \multicolumn{1}{c}{$A$} & \multicolumn{1}{c}{$B$} \\\cline{3-4}
\multirow{4}*{Player $X$} & $A$ & $\begin{gathered}(x,\\
y)\end{gathered}$ & $\begin{gathered}(x,\\
y)\end{gathered}$ \\\cline{3-4}
& $B$ & $\begin{gathered}(x,\\
y)\end{gathered}$ & $\begin{gathered}(x,\\
y)\end{gathered}$ \\\cline{3-4}
\end{tabular}
\end{table}
\end{document}
或使用makecell
包中的宏makecell
:
\documentclass{article}
\usepackage{makecell, multirow}
\setcellgapes{3pt}
\begin{document}
\begin{table}
\makegapedcells
\begin{tabular}{cc|c|c|}
& \multicolumn{1}{c}{} & \multicolumn{2}{c}{Player $Y$}\\
& \multicolumn{1}{c}{} & \multicolumn{1}{c}{$A$} & \multicolumn{1}{c}{$B$} \\\cline{3-4}
\multirow{4}*{Player $X$} & $A$ & \makecell{$(x,$\\
$ y)$} & \makecell{$(x,$\\
$ y)$} \\\cline{3-4}
& $A$ & \makecell{$(x,$\\
$ y)$} & \makecell{$(x,$\\
$ y)$} \\\cline{3-4}
\end{tabular}
\end{table}
\end{document}
答案2
或者不带任何其他包:
\documentclass{article}
\usepackage{multirow,array}
\newcolumntype{C}{>{$}c<{$}}
\begin{document}
\begin{table}
\begin{tabular}{cc|C|C|}
& \multicolumn{1}{c}{} & \multicolumn{2}{c}{Player $Y$}\\
& \multicolumn{1}{c}{} & \multicolumn{1}{c}{$A$} & \multicolumn{1}{c}{$B$} \\\cline{3-4}
\multirow{4}*{Player $X$} & \multirow{2}*{$A$} & (x, & (x, \\
& & y) & y) \\\cline{3-4}
& \multirow{2}*{$B$} & (x, & (x, \\
& & y) & y) \\\cline{3-4}
\end{tabular}
\end{table}
\end{document}