Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to center a payoff table asymmetrically but I give up and I ask to you.
The problem is that this type of table appears different than how LaTeX sees it. In fact, the first column should not be considered part of the table when centering. How can I tell this to LaTeX?

Here is the table:

enter image description here

As you see the table appears right shifted.
And here is the code found on tex.stackexchange.com and modified:

\documentclass{article}
\usepackage{caption}
\usepackage{adjustbox}
\newcommand{\mc}[3]{\multicolumn{#1}{#2}{#3}}

\begin{document}

\begin{center}
\begin{tabular}{rcccc}
\label{tab:inspectionGame}
&&$a$&$b$\\
\cline{3-4}
&\multicolumn{1}{p{0.3cm}}{\vfill\centering$A$}&
\multicolumn{1}{|p{1.5cm}}{\hfill $4$\newline $3$\hfill}&
\multicolumn{1}{|p{1.5cm}|}{\hfill $1$\newline $-3$\hfill}\\
\cline{3-4}
&\multicolumn{1}{p{0.3cm}}{\vfill\centering$B$}&
\multicolumn{1}{|p{1.5cm}}{\hfill $4$\newline $-3$\hfill}&
\multicolumn{1}{|p{1.5cm}|}{\hfill $-1$\newline $-4$\hfill}\\\cline{3-4}
\end{tabular}
\captionof{figure}{ Ash nazg durbatulûk, ash nazg gimbatul.}
\end{center}

\end{document}

EDIT: curiously someone had exactly my same problem (Center table by end of cell) just few hours ago. I try to apply that solution and if it works I'll delete my question.

EDIT2: Maybe that solution is not exactly what I need or maybe I'm still too noob to generalize :-(

share|improve this question
    
Take a look a this question, it may be usefull for you tex.stackexchange.com/questions/162046/… –  Tarass Feb 24 at 9:48
    
@Tarass thank you, but it's what I said in my EDITS ;-) I'm still trying, anyway. –  HAL9000 Feb 24 at 9:51
2  
It's a rather visual thing so exact measuring and ignoring first column (which you could do) may not look right, I'd simply put \hspace*{-3em}\begin{tabular}{rcccc} and adjust the -3em to whatever looks right. –  David Carlisle Feb 24 at 9:55
    
@DavidCarlisle I don't know if it's a solution or a workaround but it works great for my problem, thank you! –  HAL9000 Feb 24 at 9:59

3 Answers 3

up vote 8 down vote accepted

Make the left labels zero wide, and also remove the intercolumn space around the first column. I also straightened the input.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{array}
\usepackage{caption}

\newcommand{\leftlabel}[1]{%
  \makebox[0pt][r]{#1\hspace{\tabcolsep}}%
}
\newcommand{\toplabels}[2]{%
  \multicolumn{1}{@{}c@{}}{}&\multicolumn{1}{c}{#1}&\multicolumn{1}{c}{#2}
}
\newcommand{\payoff}[2]{%
  \hfill#1\newline#2\hfill
}

\begin{document}

\begin{center}
%% just to show the center
\hspace*{\fill}\hspace{-.2pt}\rule{0.4pt}{1cm}\hspace*{\fill}

\begin{tabular}{@{}r@{}|m{1.5cm}|m{1.5cm}|}
\toplabels{$a$}{$b$}\\
\cline{2-3}
\leftlabel{$A$} & \payoff{$4$}{$3$} & \payoff{$1$}{$-3$} \\
\cline{2-3}
\leftlabel{$B$}& \payoff{$4$}{$-3$} & \payoff{$-1$}{$-4$} \\
\cline{2-3}
\end{tabular}
\captionof{figure}{Ash nazg durbatulûk, ash nazg gimbatul.}
\label{tab:inspectionGame}
\end{center}

\end{document}

enter image description here

share|improve this answer
    
Thank you, this is a good solution even for similar problems! –  HAL9000 Feb 24 at 10:01
1  
@HAL9000 Note that \label must go after \caption and definitely not inside the tabular. –  egreg Feb 24 at 10:03
    
Ok, but why not inside tabular? –  HAL9000 Feb 24 at 10:06
    
@HAL9000 It must refer to the number generated by the \caption (or \captionof) command. Inside the tabular it makes no sense. –  egreg Feb 24 at 10:08
    
you're right, thank you! –  HAL9000 Feb 24 at 10:09

A solution with multirow:

        \documentclass{article}

        \usepackage{caption}
        \usepackage{array, multirow}

        \begin{document}

        \begin{center}
        $ \begin{array}{@{}r *{2}{|r@{\hspace{2.4em}}r}|}
         \multicolumn{1}{c}{}& \multicolumn{2}{c}{a}& \multicolumn{2}{c}{b}\\
        \cline{2-5}
         \multirow{2}{*}{$A$}& & 4 &  & 1 \\
           & 3 &  &  -3  & \\
        \cline{2-5}
         \multirow{2}{*}{$B$}& & 4 &  & -1 \\
           & -3 &  & -4  & \\
        \cline{2-5}
        \end{array} $
        \captionsetup{font = footnotesize}
        \captionof{figure}{Ash nazg durbatulûk, ash nazg gimbatul.}
        \label{tab:inspectionGame}
        \end{center}

        \end{document} 

enter image description here

share|improve this answer
\documentclass{article}
\usepackage{array,ragged2e}
\newcolumntype{M}[1]{>{\Centering}m{#1}}
\newcolumntype{R}{>{\RaggedLeft}p{1em}}

\newcommand{\MC}[1]{\multicolumn{1}{c}{#1}}
\newcommand\Cell[2]{$\array{@{}R @{\hspace{7mm}} R @{}} & #1\\#2 & \endarray$}

\begin{document}

\begin{table}\centering
$\begin{array}{r|M{1.6cm}|M{1.6cm}|}
 \MC{} & \MC{a}    & \MC{b}          \\ \cline{2-3}
     A & \Cell{4}{3}  & \Cell{1}{-3} \\ \cline{2-3}
     B & \Cell{4}{-3} & \Cell{-1}{-4}\\ \cline{2-3}
\end{array}$
\caption{ Ash nazg durbatulûk, ash nazg gimbatul.}\label{tab:inspectionGame}
\end{table}

\end{document}

enter image description here

share|improve this answer
    
The vertical rule in the middle of the table is not in the center of the text block; the minus signs are all wrong. –  egreg Feb 24 at 10:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.