Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
    
Here it is a good explanation. –  Manuel Nov 12 '12 at 22:40
add comment

3 Answers

up vote 6 down vote accepted

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}
share|improve this answer
add comment

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}
share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

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.