I am trying to color cells of a table with 3 rows of 2 cm width each using tabularx
and cellcolor
. I want to split an arbitrary number of cells of this table into "sub-cells" with different colors, but I can't get the spacing right even with one split-up cell:
\documentclass{article}
\usepackage{tabularx}
\usepackage{xcolor}
\usepackage{colortbl}
\begin{document}
\begin{tabularx}{6cm}{|X|>{\hsize=.2\hsize}X@{}>{\hsize=.2\hsize}X@{}>{\hsize=.2\hsize}X@{}>{\hsize=.2\hsize}X@{}>{\hsize=.2\hsize}X|X|}
\cellcolor{gray} &
\cellcolor{red} & \cellcolor{green} & \cellcolor{yellow} & \cellcolor{orange} & \cellcolor{blue} &
\cellcolor{gray} \\
1 & \multicolumn{5}{X|}{2} & 3\\
\end{tabularx}
\end{document}
As can be seen below, the blue "sub-cell" is far bigger than the red, green, yellow and orange ones, which are too small. In total, the width seems to be o.k., though.
I found some tikz
-based solutions here, but they use overlays which I am trying to avoid because I will likely be using a large number of tables and "sub-cells" for illustrating a document that I am currently working on. Is there any way to split each cell into "sub-cells" of equal width?