4

Is it possible to draw a table like the one in the attached picture? I've read documentation on the tabular environment but nothing really describes this well. The shading would be nice but the crucial part is the layout (5 columns, 2x2 merged cells on the top row and the top left 2 cells have no shading or border)

enter image description here

1
  • Here it is a good explanation.
    – Manuel
    Nov 12, 2012 at 22:40

3 Answers 3

6

colortbl can add the grey:

enter image description here

\documentclass{article}

\usepackage{colortbl,hhline}

\setlength\extrarowheight{5pt}
\definecolor{g}{rgb}{.8,.8,.8}
\begin{document}

$
\begin{array}{|*5{c|}}
\hhline{~----}
\multicolumn{1}{c|}{}&\multicolumn{2}{c|}{\cellcolor{g}c}&\multicolumn{2}{c|}{\cellcolor{g}\lnot c }\\
\hhline{~----}
\multicolumn{1}{c|}{}&\cellcolor{g}b&\cellcolor{g}\lnot b&\cellcolor{g}b&\cellcolor{g}\lnot b\\
\hline
\cellcolor{g}a&&0.33&0.03&\\
\hline
\cellcolor{g}\lnot a&&0.17&0.01&\\
\hline
\end{array}
$

\end{document}
5

This can be done using the \multicolumn which has syntax

\multicolumn{<number of cells to span>}{<justification>}{<content>}

and the \cline command which takes arguments

 \cline{<start column>-<end column>}

enter image description here

MWE

\documentclass{article}
\begin{document}

\noindent\begin{tabular}{|c|c|c|c|c|}
  \cline{2-5}
    \multicolumn{1}{c}{}  &   \multicolumn{2}{|c|}{c} &   \multicolumn{2}{|c|}{c}\\
  \cline{2-5}
  \multicolumn{1}{c}{}  &   \multicolumn{1}{|c|}{b}   &   b   &   b   &   b\\\hline
   a &      &   $.33$   &   $0.03$   &   \\\hline
   a &      &   $.33$   &   $0.03$   &   \\\hline
\end{tabular}
\end{document}
4

The following solution uses \multicolumn and \cline to get the empty cells without lines. It solves the problem of colortbl that the cell background color overprints the lines by setting the table twice, the first time with background color, the second time without.

\documentclass{article}
\usepackage{array}
\usepackage{colortbl}
\definecolor{tabgray}{gray}{.8}

\renewcommand*{\arraystretch}{1.2}

\begin{document}
\newcommand*{\MyTable}[1]{%
  \begin{tabular}{|>{#1}c|c|c|c|c|}
    \cline{2-5}
    \multicolumn{1}{l|}{} &
    \multicolumn{2}{>{#1}c|}{c} &
    \multicolumn{2}{>{#1}c|}{$\lnot$c} \\
    \cline{2-5}
    \multicolumn{1}{l|}{} &
    % b & $\lnot$b & b & $\lnot$b \\
    \multicolumn{1}{>{#1}c|}{b} &
    \multicolumn{1}{>{#1}c|}{$\lnot$b} &
    \multicolumn{1}{>{#1}c|}{b} &
    \multicolumn{1}{>{#1}c|}{$\lnot$b} \\
    \hline
    a & & 0.33 & 0.03 & \\
    \hline
    $\lnot$a & & 0.17 & 0.01 & \\
    \hline
  \end{tabular}%
}%
\leavevmode
\rlap{\MyTable{\columncolor{tabgray}}}%
\mbox{\MyTable{}}%
\end{document}

Result

You must log in to answer this question.

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