Tables with colored cells and dashed lines

I just couldn't resist proposing a TikZ-based solution:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}

\tikzset{ 
table/.style={
  matrix of math nodes,
  row sep=-\pgflinewidth,
  column sep=-\pgflinewidth,
  nodes={rectangle,draw,text width=2em,align=center},
  text depth=1ex,
  text height=2.2ex,
  nodes in empty cells,
},
column 5/.style={nodes={draw=none}},
row 5/.style={nodes={draw=none}},
}

\begin{tikzpicture}

\matrix (mat) [table]
{
& b_1 & b_2 & b_3 & & [1.5cm,between origins] b_n \\
a_1 & |[fill=gray!30]| & & & & \\
a_2 & & |[fill=gray!30]| & & & \\
a_3 & & & |[fill=gray!30]| & & \\
 & & & & & & \\[1.5cm,between origins]
a_n & & & & & |[fill=gray!30]| \\
};
\foreach \i in {1,...,6}
  \draw[dashed] ([xshift=0.5*\pgflinewidth]mat-4-\i.south west) -- ([xshift=0.5*\pgflinewidth]mat-6-\i.north west); 
\draw[dashed] ([xshift=-0.5*\pgflinewidth]mat-4-6.south east) -- ([xshift=-0.5*\pgflinewidth]mat-6-6.north east); 
\foreach \i in {1,...,6}
  \draw[dashed] ([yshift=-0.5*\pgflinewidth]mat-\i-5.north west) -- ([yshift=-0.5*\pgflinewidth]mat-\i-6.north west); 
\draw[dashed] ([yshift=0.5*\pgflinewidth]mat-6-5.south west) -- ([yshift=0.5*\pgflinewidth]mat-6-6.south west); 
\end{tikzpicture}

\end{document}

enter image description here


As the problem is only it the first row , a inelegant workaround might be to create a first phantom row:

\vspace{12pt} & & & & & \\[-12pt]

enter image description here

Complete code:

\documentclass[12pt]{article}
\usepackage{colortbl}
\usepackage{arydshln}
\usepackage{booktabs}
\usepackage{hhline}
\begin{document}
\begin{tabular}[t]{|l|c|c|c|c|c|}%
\vspace{12pt} & & & & & \\[-12pt]
\cdashline{5-5}\hhline{----~-}
& $b_1$ & $b_2$ & $b_3$ & \hspace{0.4in} & $b_n$\\
\cdashline{5-5} \hhline{|----~-|}
$a_1$ & \cellcolor[gray]{0.85} & & & &\\
\cdashline{5-5} \hhline{|----~-|}
$a_2$ & & \cellcolor[gray]{0.85} & & &\\
\cdashline{5-5} \hhline{|----~-|}
$a_3$ & & & \cellcolor[gray]{0.85} & &\\
\cdashline{5-5} \hhline{|----~-|}
\multicolumn{1}{:c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{}\\
\multicolumn{1}{:c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{}\\
\cdashline{5-5} \hhline{|----~-|}
$a_n$ & & & & & \cellcolor[gray]{0.85}\\
\cdashline{5-5} \hhline{|----~-|}
\end{tabular}
\end{document}