我怎样才能重现这种嵌套块设计?

我怎样才能重现这种嵌套块设计?

我有一张描绘嵌套块的图来说明协议堆栈 - 有这个包吗?我怎样才能获得类似的结果?

EFAIL 图

图片来源

答案1

在此处输入图片描述

  1. 编译以下文件生成bg-black.pdf
%bg-black.tex
\documentclass{standalone}
\usepackage{tikz}
\usepackage{expl3}
\usepackage{xcolor}
\usetikzlibrary{backgrounds}
\begin{document}
\ExplSyntaxOn
% set line style
\tikzset{
    linestyle/.style={
        color=black!40
    }
}
% spacing of lines
\fp_new:N \l_b_fp
\fp_set:Nn \l_b_fp {0.1}

\newcommand{\drawlines}{
    \fp_set:Nn \l_tmpa_fp {\l_b_fp}
    \fp_do_while:nn {\l_tmpa_fp < 1.0} {
        \tl_set:Nx \l_tmpa_tl {0, \fp_use:N \l_tmpa_fp}
        \tl_set:Nx \l_tmpb_tl {\fp_eval:n {(1 - \l_tmpa_fp)}, 1.0}
        \draw[linestyle] (\tl_use:N \l_tmpa_tl)--(\tl_use:N \l_tmpb_tl);
        \fp_add:Nn \l_tmpa_fp {\l_b_fp}
    }
    \fp_set:Nn \l_tmpa_fp {-\l_b_fp}
    \fp_do_while:nn {\l_tmpa_fp > -1.0} {
        \tl_set:Nx \l_tmpa_tl {\fp_eval:n {-\l_tmpa_fp}, 0.0}
        \tl_set:Nx \l_tmpb_tl {1.0, \fp_eval:n {\l_tmpa_fp + 1.0}}
        \draw[linestyle] (\tl_use:N \l_tmpa_tl)--(\tl_use:N \l_tmpb_tl);
        \fp_add:Nn \l_tmpa_fp {-\l_b_fp}
    }
    \draw[linestyle] (0.0,0.0)--(1.0,1.0);
}
\ExplSyntaxOff
\begin{tikzpicture}[background rectangle/.style={fill=white},show background rectangle]
\clip (0.1,0.1) rectangle + (0.9, 0.9);
\drawlines
\end{tikzpicture}
\end{document}
  1. 编译以下文件生成bg-orange.pdf
%bg-orange.tex
\documentclass{standalone}
\usepackage{tikz}
\usepackage{expl3}
\usepackage{xcolor}
\usetikzlibrary{backgrounds}
\begin{document}
\ExplSyntaxOn
% set line style
\tikzset{
    linestyle/.style={
        color=orange!70
    }
}
% spacing of lines
\fp_new:N \l_b_fp
\fp_set:Nn \l_b_fp {0.1}

\newcommand{\drawlines}{
    \fp_set:Nn \l_tmpa_fp {\l_b_fp}
    \fp_do_while:nn {\l_tmpa_fp < 1.0} {
        \tl_set:Nx \l_tmpa_tl {0, \fp_use:N \l_tmpa_fp}
        \tl_set:Nx \l_tmpb_tl {\fp_eval:n {(1 - \l_tmpa_fp)}, 1.0}
        \draw[linestyle] (\tl_use:N \l_tmpa_tl)--(\tl_use:N \l_tmpb_tl);
        \fp_add:Nn \l_tmpa_fp {\l_b_fp}
    }
    \fp_set:Nn \l_tmpa_fp {-\l_b_fp}
    \fp_do_while:nn {\l_tmpa_fp > -1.0} {
        \tl_set:Nx \l_tmpa_tl {\fp_eval:n {-\l_tmpa_fp}, 0.0}
        \tl_set:Nx \l_tmpb_tl {1.0, \fp_eval:n {\l_tmpa_fp + 1.0}}
        \draw[linestyle] (\tl_use:N \l_tmpa_tl)--(\tl_use:N \l_tmpb_tl);
        \fp_add:Nn \l_tmpa_fp {-\l_b_fp}
    }
    \draw[linestyle] (0.0,0.0)--(1.0,1.0);
}
\ExplSyntaxOff
\scalebox{1}[-1]{%
\begin{tikzpicture}[background rectangle/.style={fill=white},show background rectangle]
\clip (0.1,0.1) rectangle + (0.9, 0.9);
\drawlines
\end{tikzpicture}}
\end{document}
  1. 编译主文档
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{tcolorbox}
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{amsmath}

\tcbuselibrary{skins,breakable, hooks}

\begin{document}



\tcbset{
    stdbox/.style={
        enhanced jigsaw,
        title=\textcolor{black}{Try},
        arc=0mm,
        sharp corners,
        colframe=black,
        colback=white,
        attach boxed title to top left,
        boxed title style={
            enhanced,
            arc=0mm,
            sharp corners,
            colframe=black,
            colback=white,
            bottomrule=0pt
        },
        left=1mm,
        right=1mm,
        top=1mm,
        bottom=1mm
    }
}


\newtcolorbox{bgbox}[3]{
stdbox,
interior style tile={}{#1},
title={\color{black}\bfseries #2},
frame code app={
    \node[yshift=2ex,anchor=east] at (frame.north east) {\small\ttfamily #3};
}
}

\newtcolorbox{ctbox}[2]{
stdbox,
enhanced,
title={\color{black}\bfseries #1},
frame code app={
    \node[yshift=2ex,anchor=east] at (frame.north east) {\small\ttfamily #2};
}
}

\begin{bgbox}{bg-black}{SEIP (Tag 18) $\lVert$ Length}{}
\begin{bgbox}{bg-orange}{CD (Tag 8) $\lVert$ Length}{<encrypted>}
\begin{ctbox}{LD (Tag 11) $\lVert$ Length}{<compressed>}
\texttt{Content type: ...}
\end{ctbox}
\end{bgbox}
\begin{ctbox}{MDC (Tag 19) $\lVert$ Length}{}
\texttt{qwerty...}
\end{ctbox}
\end{bgbox}


\end{document}

相关内容