2

I am facing a problem with centering the text inside the boxes:

\documentclass[a4paper,fontsize=12pt,a4paper,DIV=10,BCOR=10mm,twoside,titlepage=false,openany,pagesize]{scrbook}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{blindtext}
\setkomafont{disposition}{\normalfont\bfseries}

\usepackage{tikz}
\usetikzlibrary{calc,matrix,positioning}
\begin{document}

\begin{figure}[h]
\centering
\caption{test}
\label{test}
\begin{tikzpicture}[element/.style={text width=1.8cm,minimum height=0.85cm}]
\matrix (m) [matrix of nodes,nodes={element},column sep=-\pgflinewidth, row sep=-\pgflinewidth,]{
         & Cooperate & Defect  \\
Cooperate & |[draw]|3+x,3+x & |[draw]|1+y,4 \\
Defect & |[draw]|4,1+y & |[draw]|2,2 \\
};
\node[above=0.25cm] at ($(m-1-2)!0.5!(m-1-3)$){\textbf{Actor A}};
\node[rotate=90] at ($(m-2-1)!0.5!(m-3-1)+(-1.25,0)$){\textbf{Actor B}};
\end{tikzpicture}
\end{figure}
\end{document}
1
  • align=center to the nodes. Jul 22, 2014 at 13:54

1 Answer 1

2

Pass the align=center option to the nodes. I also changed to a matrix of math nodes to have the proper math-mode for the math expressions (regular text was produced with the help of \text from amsmath) and increased the text width:

    \documentclass[a4paper,fontsize=12pt,a4paper,DIV=10,BCOR=10mm,twoside,titlepage=false,openany,pagesize]{scrbook}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{blindtext}
\setkomafont{disposition}{\normalfont\bfseries}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc,matrix,positioning}
\begin{document}

\begin{figure}[h]
\centering
\caption{test}
\label{test}
\begin{tikzpicture}[element/.style={text width=2.5cm,minimum height=0.85cm,align=center}]
\matrix (m) [matrix of math nodes,nodes={element},column sep=-\pgflinewidth, row sep=-\pgflinewidth,]{
         & \text{Cooperate} & \text{Defect}  \\
\text{Cooperate} & |[draw]|3+x,3+x & |[draw]|1+y,4 \\
\text{Defect} & |[draw]|4,1+y & |[draw]|2,2 \\
};
\node[above=0.25cm] at ($(m-1-2)!0.5!(m-1-3)$){\textbf{Actor A}};
\node[rotate=90] at ($(m-2-1)!0.5!(m-3-1)+(-1.25,0)$){\textbf{Actor B}};
\end{tikzpicture}
\end{figure}
\end{document}

enter image description here

You must log in to answer this question.

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