I want to center align the word prediction in the following. I would appreciate any help in doing so.

\documentclass[professionalfont, fleqn]{beamer}



 box/.style = {draw,rectangle,minimum size=1.0cm,text
\matrix (conmat) [row sep=0cm,column sep=0cm,ampersand
replacement=\&] {
\node (tpos) [box,label=left:\( \mathbf{p'} \),label=above:\(
\mathbf{p} \),] {};
  \& \node (fneg) [box,label=above:\textbf{n},] {$\checkmark$}; \\
 \node (fpos) [box,label=left:\( \mathbf{n'} \),] {$\checkmark$};
  \& \node (tneg) [box] {$\checkmark$}; \\

\node [left=.05cm of conmat,text width=1.5cm,align=center]
{\textbf{actual \\ value}};
\node [above=.05cm of conmat] {\textbf{prediction}};


2 Answers 2


Word prediction is centered with your matrix because it includes label's row and column.

(Added by Andrew Stacey: see picture below, the extra square is the "bounding box" of the matrix and the coordinate (conmat) is at the centre of this box)

box around matrix

If you want to align center of prediction with the central line of your matrix you can use something like

\node [above=.05cm of conmat.north-|tpos.east] {\textbf{prediction}};

conmat.north|-tpos.east represents the point interesction of a horizontal line crossing tpos.south and a vertical one corssing conmat.north.

In a similar way you can align actual value with your matrix horizontal division line:

\node [left=.05cm of conmat.west|-tpos.south,text width=1.5cm,align=center]{\textbf{actual \\ value}};

enter image description here

  • 1
    I'd just gotten as far as compiling the picture showing how big the matrix node is, rather than waste it I thought it worth while adding to your answer - hope you don't mind. Jul 26, 2012 at 14:49
  • @AndrewStacey: of course! editions like this one are always welcome!
    – Ignasi
    Jul 27, 2012 at 16:56

I think a little structure would be beneficial if you are going to make more complicated ones similar to this...



\matrix (conmat) [
matrix of math nodes, 
nodes in empty cells,
ampersand replacement=\&,
nodes={minimum size=1cm,outer sep=0,inner sep=0,anchor=center}
] {
                     \& \checkmark \\
\checkmark           \& \checkmark \\
\draw (conmat.north) -- (conmat.south) (conmat.east) -- (conmat.west);
\node[above=2mm of conmat-1-1] {\(\mathbf{p}\)};
\node[left =2mm of conmat-1-1] {\(\mathbf{p'}\)}; 
\node[left =2mm of conmat-2-1] {\(\mathbf{p'}\)};
\node[above=2mm of conmat-1-2] {\textbf{n}};

\node [left= 4mm of conmat,text width=1.5cm,align=center] {\textbf{actual \\ value}};
\node [above=4mm of conmat] {\textbf{prediction}};

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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