2

Based on this question I would like to add a background around multiple tcboxeditemize environments from the tcolorbox package. In my MWE the tcboxeditemize rasters remains in the background and I only draw on the tikz layers. Is there any chance to get only the big gray rectangle in the background? Putting the whole thing in a tikzpicture environment does not seem to work.


MWE

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[most]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{fit}
\usetikzlibrary{positioning}

\begin{document}

\tikzset{
    My RectLabel Style/.style={
        draw=black
       ,fill=white
    }
}
%
\tikzset{
    My Bg Style/.style={
        inner xsep=10pt
       ,inner ysep=10pt
       ,draw=black
       ,thick
       ,fill=lightgray % should have this color
       %,fill=none
    }
}
% 
\definecolor{myboxcolor}{RGB}{240,240,240}
\definecolor{myrastercolor}{RGB}{220,220,220}
% 
\tcbset{
    myraster/.style={
        raster columns=#1, 
        raster equal height, 
        size=small, 
        rounded corners, 
        frame hidden,
        colback=myrastercolor,
        halign=center
    },
    mybox/.style={
        colframe=black,
        colback=myboxcolor,
        sharp corners,
        coltitle=black,
        fontupper=\small,
        enhanced,
        attach boxed title to top center={yshift*=-\tcboxedtitleheight/2},
        boxed title style={
            colback=white,
            colframe=black,
            sharp corners,
            remember as={title #1},
        },
        title={#1},
        remember as={#1},
        left skip=0.5cm,
        right skip=0.5cm,
    }
}

\pgfdeclarelayer{bg}    % declare background layer
\pgfsetlayers{bg,main}  % set the order of the layers (main is the standard layer)

\begin{tcboxeditemize}%
[%inner boxes properties
    myraster=3
]{%outer box properties
    mybox={Client Layer}
}
    \tcbitem Library 2-1
    \tcbitem Library 2-2
    \tcbitem Library 2-3
    \tcbitem Library 2-4
    \tcbitem Library 2-5
\end{tcboxeditemize}
\vspace*{.5cm}
\begin{tcboxeditemize}%
[%inner boxes properties
    myraster=3
]{%outer box properties
    mybox={Utility Layer}
}
    \tcbitem Library 1-1
    \tcbitem Library 1-2
    \tcbitem Library 1-3
\end{tcboxeditemize}
\vspace*{.5cm}
\begin{tcboxeditemize}%
[%inner boxes properties
    myraster=3
]{%outer box properties
    mybox={Base Layer}
}
    \tcbitem Library 1-1
    \tcbitem Library 1-2
    \tcbitem Library 1-3
\end{tcboxeditemize}

\tikz[remember picture, overlay]{

    \draw[-latex] (title Base Layer) -- (Utility Layer);
    \draw[-latex] (title Utility Layer) -- (Client Layer);


    \begin{pgfonlayer}{bg}    % select the background layer
        \node[fit={(Base Layer) (Client Layer) (title Client Layer)}, My Bg Style] (rect2) {};
        \node[My RectLabel Style,anchor=west] (rect2Label) at ($(rect2.north west)!0.1!(rect2.north east)$) {Lib};
    \end{pgfonlayer} 

}

Result

Thanks Ignasi. This is the result I am very pleased with.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[most]{tcolorbox}

\begin{document}

\definecolor{mybgcolor}{RGB}{250,250,250}
\definecolor{myboxcolor}{RGB}{240,240,240}
\definecolor{myrastercolor}{RGB}{220,220,220}

\tcbset{
    myraster/.style={
        raster columns=#1, 
        raster equal height,
        raster row skip=2mm,
        size=small, 
        rounded corners, 
        frame hidden,
        colback=myrastercolor,
        halign=center,
        raster halign=center % center last line if not full
    }
  ,mybox/.style={
        colframe=black,
        colback=myboxcolor,
        sharp corners,
        coltitle=black,
        fontupper=\small,
        enhanced,
        attach boxed title to top center={yshift*=-\tcboxedtitleheight/2},
        boxed title style={
            colback=white,
            colframe=black,
            sharp corners,
            remember as={title #1},
        },
        title={#1},
        remember as={#1},
    }
  ,mybgbox/.style={
        colback=mybgcolor
      ,colframe=gray%red!50!black
      ,coltitle=black
      ,fontupper=\small
      ,enhanced
      ,attach boxed title to top left={
          xshift=5mm
        ,yshift*=-\tcboxedtitleheight/2
        }
      ,boxed title style={
            colback=white
          ,colframe=black
          ,sharp corners
          ,remember as={title #1}
        }
      ,title={#1}
      ,remember as={#1}
    }
}

\begin{tcbraster}[
  raster columns=1
,raster row skip=8mm
]
  \begin{tcboxedraster}[
    raster columns=1
  ,raster row skip=5mm
  ]{
    mybgbox={Lib}
  }
    \begin{tcboxeditemize}%
    [%inner boxes properties
      myraster=3
    ]{%outer box properties
      mybox={Client Layer}
    }
      \tcbitem Library 2-1
      \tcbitem Library 2-2
      \tcbitem Library 2-3
      \tcbitem Library 2-4
      \tcbitem Library 2-5
    \end{tcboxeditemize}
    \vspace*{.5cm}
    \begin{tcboxeditemize}%
    [%inner boxes properties
      myraster=3
    ]{%outer box properties
      mybox={Utility Layer}
    }
    \tcbitem Library 1-1
    \tcbitem Library 1-2
    \tcbitem Library 1-3
    \end{tcboxeditemize}
    \vspace*{.5cm}
    \begin{tcboxeditemize}%
    [%inner boxes properties
      myraster=3
    ]{%outer box properties
      mybox={Base Layer}
    }
      \tcbitem Library 1-1
      \tcbitem Library 1-2
      \tcbitem Library 1-3
    \end{tcboxeditemize}
  \end{tcboxedraster}
\end{tcbraster}

\tikz[remember picture, overlay]{
  \draw[-latex] (title Base Layer) -- (Utility Layer);
  \draw[-latex] (title Utility Layer) -- (Client Layer);
}

\end{document}

\end{document}
3

You can use a raster of rasters. See section "14.6 Rasters inside Rasters". It's important to read it to understand what happens. You need a tcolorbox (tboxedraster in following code) inside the external raster.

In this case raster row skip can be applied to fix distance between rows, but as this option also affects inner boxes, a raster row skip=2mm has been included in myraster definition to keep default separation between inner rows.

\documentclass{article}
\usepackage{lipsum}
\usepackage[most]{tcolorbox}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}

\tcbset{
    myraster/.style={
        raster columns=#1, 
        raster equal height, 
        raster row skip=2mm,
        size=small, 
        rounded corners, 
        frame hidden, 
        colback=gray,
        halign=center,
        raster halign=center,
    },
    mybox/.style={
        colframe=black,
        sharp corners,
        coltitle=black,
        fontupper=\small,
        enhanced,
        attach boxed title to top center={yshift*=-\tcboxedtitleheight/2},
        boxed title style={
            colback=white,
            colframe=black,
            sharp corners,
            remember as={title #1},
        },
        title={#1},
        remember as={#1},
    }
}

\begin{document}
\lipsum[1]

\begin{tcbraster}[raster columns=1, raster row skip=8mm]
\begin{tcboxedraster}[raster columns=1, raster row skip=8mm]{colback=red!30, colframe=red!50!black}
\begin{tcboxeditemize}%
[%inner boxes properties
    myraster=3
]{%outer box properties
    mybox={Layer 2}
}
\tcbitem Library 2-1
\tcbitem Library 2-2
\tcbitem Library 2-3
\tcbitem Library 2-4
\tcbitem Library 2-5
\end{tcboxeditemize}

\begin{tcboxeditemize}%
[%inner boxes properties
    myraster=3
]{%outer box properties
    mybox={Layer 1}
}
\tcbitem Library 1-1
\tcbitem Library 1-2
\tcbitem Library 1-3
\end{tcboxeditemize}
\end{tcboxedraster}
\end{tcbraster}

\tikz[remember picture, overlay] \draw[<-, line width=.5mm] (Layer 2)--(title Layer 1);
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.