4

I am trying to create the following game matrix and am wondering how exactly can I vertically align the cell contents? Especially since I need them to be offset differently in the same cell.Is this doable or should I cheat with with a separate column? Either ways what's the simple and best way to offset the contents?

enter image description here

2 Answers 2

6

Without sub- and superscripts:

\documentclass{article}

\usepackage{multirow}
\begin{document}


\begin{tabular}{|c|c|lr|lr|}
\hline
&\multicolumn{5}{c|}{Adversary}\\
\hline
\multirow{5}{*}{Defender}
&&
\multicolumn{2}{c|}{Terminal 1}&
\multicolumn{2}{c|}{Terminal  2}\\
\cline{2-6}
&\multirow{2}{*}{Terminal 1}&
 & -3 && 1\\
&&5  && -1&\\
\cline{2-6}
&\multirow{2}{*}{Terminal 2}
& & -3 && 1\\
&&5 & & -1 & \\
\hline
\end{tabular}

\end{document}

enter image description here

But I'd rather write $-3$ instead of 3 and so on.

0
5

enter image description here

\documentclass{article}

\usepackage{array,multirow}

\newcommand\zz[2]{$%
{}_{\ifnum#1<0 \else\hphantom{-}\fi#1}%
\qquad
{}^{\ifnum#2<0 \else\hphantom{-}\fi#2}%
$}

\begin{document}
\setlength\extrarowheight{3pt}

\begin{tabular}{|c|c|c|c|}
\hline
&\multicolumn{3}{c|}{Adversary}\\ \hline
\multirow{3}{*}{Defender}&&Terminal 1&Terminal 2\\ \cline{2-4}
&Terminal 1&\zz 5 {-3}&\zz {-1} 1\\ \cline{2-4}
&Terminal 2&\zz {-5}  5&\zz 2 {-1}\\ \hline
\end{tabular}
\end{document}
6
  • sorry about missing space in terminal 2 :-) May 8, 2013 at 23:48
  • Oh that's such a nice and simple trick! Of course, sub/super scripts :) Ha! Why didn't I think of it. Smart. +1. But the numbers don't align vertically (5, -5) and (-1, 2). Just add spaces (or something better?)
    – PhD
    May 8, 2013 at 23:58
  • @PhD Cheat TeX by \hphantom{-} at positive numbers?
    – kan
    May 9, 2013 at 0:04
  • @kan - I'm not sure how to use that. Sorry...
    – PhD
    May 9, 2013 at 0:07
  • @PhD Add \hphantom{-} before 5 (inside the $...$ and see what happens.
    – kan
    May 9, 2013 at 0:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .