0

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

8

2 Answers 2

3

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

2
  • This is giving me: "Undefined control sequence. \Rowstyle"
    – tail
    May 16, 2022 at 14:50
  • The name of that command is \RowStyle and not \Rowstyle but, if the command \RowStyle is not accepted, your version of nicematrix is probably too old. You need at least version 6.3 of 2022/10/18. May 16, 2022 at 16:20
1

With tblr of tabularray and by use S column type for columns with numbers (that they are aligned at the decimal point):

\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}

\begin{document}
    \begin{table}[ht]
\sisetup{round-mode = places,
         round-precision = 2}
    \begin{tblr}{hlines, vlines,
                colspec = {c S[table-format=4.2{ms}]
                             S[table-format=3.2{ms}]
                             S[table-format=2.2{ms}]
                             S[table-format=1.2{ms}]
                          },
                 row{1} = {bg=black, fg=white},
                 row{2} = {bg=gray,  fg=white},
                 }

\SetCell[r=2]{h, bg=black}   {{{Semestre}}}
    &  \SetCell[c=2]{c} {{{Senza Vista}}}
            &       &   \SetCell[c=2]{c} {{{Con Vista}}}
                                            &           \\
    & {{{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{tblr}
    \end{table}
\end{document}

It need only one compilation for final result:

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .