TikZ:在 tcolorbox tcboxeditemize 的背景中绘制

TikZ:在 tcolorbox tcboxeditemize 的背景中绘制

基于这个问题我想添加来自多个tcboxeditemize环境的背景tcolorbox包。在我的 MWE 中,tcboxeditemize 栅格保留在背景中,我只在图层上绘图tikz。有没有可能只在背景中得到大灰色矩形?将整个东西放在环境中tikzpicture似乎不起作用。


平均能量损失

\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} 

}

结果

谢谢 Ignasi。这是我非常满意的结果。

\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}

答案1

您可以使用raster of rasters。请参阅“14.6 栅格内的栅格”。阅读它以了解发生了什么很重要。您需要在外部 内有一个tcolorbox(在下面的代码中) 。tboxedrasterraster

在这种情况下raster row skip可以应用于固定行之间的距离,但由于此选项也会影响内部框,因此在定义raster row skip=2mm中包含了myraster保持内行之间的默认分隔。

\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}

在此处输入图片描述

相关内容