I would like to add a label that is diagonal to the following box, underneath the n', such that it is horizontally just below the box. Basically, I would like to "subtract" the difference between the content in the two cells. I'd like to add a label that says "Diff" just off the bottom left corner and then place the difference just below (p, n') box, outside of it.

For a picture of the box, see an earlier questions: making a box in beamer -- center aligning the title

Thank you very much for your help!

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


1 Answer 1


I think beamer part is not related to this and previous question as it is only using TikZ content for just one frame. Just addding \node[below left= 2mm of conmat.south west] {diff}; to my answer given in the previous question linked is a solution.



\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[below left= 2mm of conmat.south west] {diff};

\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

  • how can i add color to a cell?
    – J G
    Jul 26, 2012 at 18:16
  • @JG add |[fill=red]| to any cell together with inner sep=0, to the matrix options.
    – percusse
    Jul 26, 2012 at 19:00
  • Thank you! Also, how would I write normal text instead of the checkmark. When I tried to, it came out all italicized and without any space between the words.
    – J G
    Jul 26, 2012 at 23:07
  • @JG That's due to the matrix of math nodes option as it automatically makes every node text in math mode. You can change it to matrix of nodes but then you need to introduce the \(...\) to math text again or you keep the same option and use \text{regular text here}. So it depends which one is more common.
    – percusse
    Jul 26, 2012 at 23:10
  • Thank you! Could you please give me a more concrete example where to put that line in about color. I'm sorry but I do not understand what you mean. I also don't fully understand how to apply your last answer on the \text. Could you please give me a concrete example with the code? That would help so much. Thank you!
    – J G
    Jul 27, 2012 at 0:34

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.