TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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}};

share|improve this question
up vote 5 down vote accepted

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

share|improve this answer
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. – Loop Space Jul 26 '12 at 14:49
@AndrewStacey: of course! editions like this one are always welcome! – Ignasi Jul 27 '12 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

share|improve this answer

Your Answer


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.