Tabularx multicolumn

tablestabularxtcolorbox

Hello this is my table:

\documentclass[12pt, oneside,titlepage]{book} % add a4paper
\usepackage[italian]{babel}
\usepackage{geometry}
%\geometry{a4paper, top = 2cm, right = 2cm, left = 2cm, bottom = 2cm}

% Tabelle
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tcolorbox}
\usepackage{tabularx}
\usepackage{array}
\usepackage{colortbl}
\tcbuselibrary{skins}
\newcolumntype{Y}{>{\raggedleft\arraybackslash}X}
\tcbset{tab1/.style={fonttitle=\bfseries\large,fontupper=\normalsize\sffamily,
        colback=yellow!10!white,colframe=red!75!black,colbacktitle=Salmon!40!white,
        coltitle=black,center title,freelance,frame code={
            \foreach \n in {north east,north west,south east,south west}
            {\path [fill=red!75!black] (interior.\n) circle (3mm); };},}}
\tcbset{tab2/.style={enhanced,fonttitle=\bfseries,fontupper=\normalsize\sffamily,
        colback=yellow!10!white,colframe=red!50!black,colbacktitle=Salmon!40!white,
        coltitle=black,center title}}
    
\begin{document}
    \begin{tcolorbox}[tab2,tabularx={X|Y|Y|Y},title=Viste materializzate,boxrule=0.5pt] 
    Nome vista & Tempo (s) & Dimensione & Guadagno \\ \hline \hline
    
    A & 0.2 & 16 kB & 0 \%\\ \hline
    B & 10 & 4336 kB & 1 \% \\ \hline
    
\end{tcolorbox}
\end{document}

But I would like to get the template similar to this, that is with "Senza vista" node and "senza indici" and "con indici" children and so on. How can I do?

template

Best Answer

With {NiceTabular} of nicematrix :

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\sffamily
\begin{NiceTabular}{ccccc}[hvlines]
\RowStyle[color=white,rowcolor=black]{}
Semestre & \Block{1-2}{Senza Vista} && \Block{1-2}{Con Vista} \\
\RowStyle[rowcolor=black]{}
         & \RowStyle[color=white,rowcolor=gray]{}
           Senza Indici & Con Indici & Senza Indici & Con Indici \\
1 & 284.9 ms & 119.6 ms & 44.7 ms & 1.8 ms \\
2 & 636.66 ms & 137.4 ms & 45.4 ms & 3.88 ms \\
3 & 962.7 ms & 157 ms & 55.7 ms & 4.6 ms \\
4 & 1340 ms & 190.2 ms & 87.6 ms & 6.5 ms 
\end{NiceTabular}


\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code