[Tex/LaTex] Table with TikZ

colornodestablestikz-pgf

I should create a table like the one here as example. I think that the best way to do a table like this one is generate some labels and use them to colorize the nodes in order to make it more automatic. First column are categorized colors and right column are a color spectrum. My question is if you have to face a problem like this one which tools from TikZ would you use to generate such table. I started to code the table in TikZ but I was defining everything: The position of the nodes, all the line intersecting points to create the lines afterwards. The code gets huge, nasty, and horrible to check if i I've placed the colors properly.

Therefore, do you have any suggestions of how would you do this job?

enter image description here

Best Answer

This can give you a starting point:

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

\definecolor{redi}{RGB}{255,38,0}
\definecolor{redii}{RGB}{200,50,30}
\definecolor{yellowi}{RGB}{255,251,0}
\definecolor{bluei}{RGB}{0,150,255}
\definecolor{blueii}{RGB}{135,247,210}
\definecolor{blueiii}{RGB}{91,205,250}
\definecolor{blueiv}{RGB}{115,244,253}
\definecolor{bluev}{RGB}{1,58,215}
\definecolor{orangei}{RGB}{240,143,50}
\definecolor{yellowii}{RGB}{222,247,100}
\definecolor{greeni}{RGB}{166,247,166}

\tikzset{ 
table/.style={
  matrix of nodes,
  row sep=-\pgflinewidth,
  column sep=-\pgflinewidth,
  nodes={rectangle,draw=black,text width=1.25ex,align=center},
  text depth=0.25ex,
  text height=1ex,
  nodes in empty cells
  },
texto/.style={font=\footnotesize\sffamily},
title/.style={font=\small\sffamily}
}


\newcommand\CellText[2]{%
  \node[texto,left=of mat#1,anchor=east]
  at (mat#1.west)
  {#2};
}

\newcommand\SlText[2]{%
  \node[texto,left=of mat#1,anchor=west,rotate=75]
  at ([xshift=3ex]mat#1.north)
  {#2};
}

\newcommand\RowTitle[2]{%
\node[title,left=6.3cm of mat#1,anchor=west]
  at (mat#1.north west)
  {#2};
}


\begin{document}


\begin{tikzpicture}[node distance =0pt and 0.5cm]

\matrix[table] (mat11) 
{
|[fill=redi]| & & & \\
|[fill=redi]| & & & \\
|[fill=redi]| & & & \\
};
\matrix[table,right=of mat11] (mat12) 
{
|[fill=orangei]| & |[fill=yellowii]| & |[fill=blueii]| & |[fill=blueiii]| \\
& |[fill=blueii]| & |[fill=greeni]| & |[fill=blueiv]| \\
& & |[fill=bluev]| & |[fill=blueiii]| \\
};
\matrix[table,below=of mat11] (mat21) 
{
|[fill=redi]| & & & \\
|[fill=redi]| & & & \\
|[fill=yellowi]| & & & \\
|[fill=yellowi]| & & & \\
};
\matrix[table,below=of mat12] (mat22) 
{
|[fill=bluev!95]| & & |[fill=yellowii]| & |[fill=orangei!80]| \\
& |[fill=yellowii]| & |[fill=bluev!80]| & |[fill=blueiii]| \\
|[fill=redii]| & |[fill=blueiii!80]| & & |[fill=bluev]| \\
|[fill=bluev]| & & |[fill=blueiii!80]| & |[fill=bluev]| \\
};
\matrix[table,below=of mat21] (mat31) 
{
|[fill=redi]| & & & \\
|[fill=bluei]| & & & \\
};
\matrix[table,below=of mat22] (mat32) 
{
|[fill=bluev]| & & |[fill=redii]| & |[fill=redii!90!black]| \\
|[fill=redii!90]| & |[fill=redii!75!black]| & |[fill=bluev]| & |[fill=bluev!80!black]| \\
};

\SlText{11-1-1}{Fibroadenoma [xx]}
\SlText{11-1-2}{Simple Cyst}
\SlText{11-1-3}{Complex Cyst}
\SlText{11-1-4}{Papilloma}

\SlText{12-1-1}{CDI}
\SlText{12-1-2}{CLI}
\SlText{12-1-3}{FA}
\SlText{12-1-4}{Cyst}

\RowTitle{11}{Background echotexture};
\CellText{11-1-1}{Homogeneous adipose-echotexture};
\CellText{11-2-1}{Homogeneous fibroglandular-echotexture};
\CellText{11-3-1}{Hoterogeneous};

\RowTitle{21}{Mass shape};
\CellText{21-1-1}{Oval};
\CellText{21-2-1}{Round};
\CellText{21-3-1}{Irregular};

\RowTitle{31}{Mass orientation};
\CellText{21-4-1}{Lobular};
\CellText{31-1-1}{Parallel to skin};
\CellText{31-2-1}{Non-parallel to skin};

\end{tikzpicture}

\end{document}

enter image description here