# How to get the following table?

I want to make this table:

Whereas, I get this one: Any suggestions for the code I wrote below?

\begin{center}
\begin{tabular}{c|cc|c|}
& $A$ & NOT $A$ & SUM\\ \hline
$B$ & $P(A$ AND$\,B)$ & $P($NOT $A$ AND$\,B)$ & $P(B)$\\
NOT $B$ &$P(A\,$NOT$\,B)$ &$P($NOT $A\,$AND NOT$\,B)$ & $P($NOT $B)$ \\ \hline
& $P(A)$ & $P($NOT $A)$& $1$\\ \hline
\end{tabular}
\end{center}

• Welcome to TeX.SE! Can the text font not be the same? – manooooh Aug 30 '18 at 1:08

With no additional packages (I am assuming that Comic Sans is not your dream):

\documentclass{article}

\begin{document}

\begin{center}
\begin{tabular}{c|cc|c|}
\multicolumn{1}{c}{}& $A$ &\multicolumn{1}{c}{ NOT $A$} &\multicolumn{1}{c}{ SUM}\\
%\hline
\cline{2-4}
$B$ & $P(A$ AND$\,B)$ & $P($NOT $A$ AND$\,B)$ & $P(B)$\\
NOT $B$ &$P(A\,$NOT$\,B)$ &$P($NOT $A\,$AND NOT$\,B)$ & $P($NOT $B)$ \\
%\hline
\cline{2-4}
& $P(A)$ & $P($NOT $A)$& $1$\\
%\hline
\cline{2-4}
\end{tabular}
\end{center}

\end{document}


This is easy with blkarray:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mathtools, blkarray}

\begin{document}

$\everymath{\displaystyle}\setlength{\BAextrarowheight}{2pt} \begin{blockarray}{cccc} & A & \text{NOT }A & \text{SUM} \\ \BAhhline{~---} \begin{block}{c|cc|c|} B & P(A\text{ AND}B) & P(\text{NOT }A\text{ AND }B) & P(B)\\ \text{NOT }B &P(A\text{ NOT }B) &P(\text{NOT }A\text{ AND NOT }B) & P(\text{NOT }B) \\ \BAhhline{~|---|} & P(A) & P(\text{NOT }A)& 1\\ \BAhhline{~---} \end{block} \end{blockarray}$

\end{document}


• please use \text{} for SUM. – corvus_192 Aug 30 '18 at 8:43
• @corvus_192: Oh! yes, I forgot this cell. It's fixed. Thanks for pointing it! – Bernard Aug 30 '18 at 9:08

Use \multicolumn command to suppress vertical ruling of specific cells. If the table width is not as you want, try to modify the width provided in {\textwidth}

\documentclass{article}
\usepackage{amsmath}
\renewcommand{\arraystretch}{1.7}
\usepackage{ragged2e}
\usepackage{tabularx}
\newcolumntype{C}{ >{ \arraybackslash \Centering } X }
\usepackage{booktabs}
\usepackage{makecell}

\begin{document}

\noindent
\begin{table*}

\centering
\begin{tabularx}{\textwidth}{>{\hsize=0.3\hsize}C |>{\hsize=1.5\hsize} C>{\hsize=1.5\hsize}C| >{\hsize=0.7\hsize}C|}
\multicolumn{1}{c}{} & \multicolumn{1}{c}{$A$} &  \multicolumn{1}{c}{$A^{'}$} & \multicolumn{1}{c}{SUM}
\\
\Xcline{2-4}{0.2mm}
$B$ & $P(A \text{ AND } B)$ & $P(\text{NOT } A \text{ AND } B)$ & $P(B)$
\\
$B^{'}$ & $P(A \text{ AND NOT } B)$ & $P(\text{NOT } A \text{ AND NOT} B)$ & $P($NOT $B)$
\\
\Xcline{2-4}{0.2mm}
& $P(A)$ & $P($NOT $A)$& $1$
\\
\Xcline{2-4}{0.2mm}
\end{tabularx}

\end{table*}

\end{document}