在 Tikz 中绘制带有阴影图案边框的块

在 Tikz 中绘制带有阴影图案边框的块

我正在尝试重新创建如图所示的框图: 在此处输入图片描述

我是乳胶的新手,我创建单个块的方式是:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings, patterns}

\begin{document}
\begin{figure}[h]\centering
    \pgfdeclareradialshading{spherebrown}{\pgfpoint{-0.8cm}{1cm}}%
    {rgb(0cm)=(1,1,1);
        rgb(1.5cm)=(0.9059,0.9059,0.5647)
    }
    \pgfdeclareradialshading{spheregreen}{\pgfpoint{-0.8cm}{1cm}}%
    {rgb(0cm)=(0.7980,0.9686,0.9255);
        rgb(1.5cm)=(0.2412,0.3941,0.0392)
    }
    \tikzstyle{block_1} = [draw,rectangle,minimum width=30mm,minimum height = 10mm, line width=0.5pt,rounded corners=2pt,gray,shading=spherebrown]
    \tikzstyle{block_2} = [draw,rectangle,minimum width=32mm,minimum height = 12mm, line width=0.5pt,rounded corners=1pt,gray,pattern=north west lines]
    \tikzstyle{block_3} = [draw,rectangle,minimum width=32mm,minimum height = 12mm, line width=0.5pt,rounded corners=1pt,gray,shading=spheregreen]
    \begin{tikzpicture}
        \node (A) at (0,0)[block_3]{};
        \node (B) at (0,0)[block_2]{};
        \node (C) at (0,0)[block_1,text width=28mm,font=\bfseries\scriptsize,align=center]{\sffamily\textcolor{black}{NOSILAC\\DSS AD9833}};
    \end{tikzpicture}
    \caption{Primjer jednog komunikacijskog sistema sa ARM Cortex M3 MCU i DDS-om}
    \label{slika:6}
\end{figure}

\end{document}

结果如下:

在此处输入图片描述

但在我看来,我在某些地方做错了,因为这对于单个块来说似乎工作量太大了,那么有没有更简单的方法来创建这样的东西?

答案1

更新

此解决方案不使用preactions和,而只使用和。第一个预操作绘制彩色背景,然后是第二个预操作绘制图案(请记住,预操作是按顺序应用的)。之后,使用 (适用于所有填充)绘制内部背景。在这种情况下,改变坐标系的比例因子没有问题(参见原始代码)。postactionspreactionspath picturepath picture

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings, patterns, positioning}

    \pgfdeclareradialshading{spherebrown}{\pgfpoint{-0.8cm}{1cm}}%
    {rgb(0cm)=(1,1,1);
        rgb(1.5cm)=(0.9059,0.9059,0.5647)
    }
    \pgfdeclareradialshading{spheregreen}{\pgfpoint{-0.8cm}{1cm}}%
    {rgb(0cm)=(0.7980,0.9686,0.9255);
        rgb(1.5cm)=(0.2412,0.3941,0.0392)
    }

\tikzset{
    myblock/.style={
        draw, rectangle, minimum width=30mm, minimum height=10mm,
        line width=.5pt, rounded corners=2pt, gray, text width=28mm,
        font=\bfseries\scriptsize\sffamily, align=center, text=black,
        preaction={shading=spheregreen},
        preaction={pattern=north west lines},
        path picture={\draw[rounded corners=2pt, gray, shading=spherebrown] ([shift={(1mm,-1mm)}]path picture bounding box.north west) rectangle ([shift={(-1mm,1mm)}]path picture bounding box.south east);},
    }
}

\begin{document}

\begin{tikzpicture}
    \node [myblock] (A) {NOSILAC\\DSS AD9833};
    \node [myblock, above right=5mm and -5mm of A] {NOSILAC\\DSS AD9833};
\end{tikzpicture}

\end{document}

在此处输入图片描述

原始答案

这项工作正在进行中。目前的解决方案仅适用于原点节点。

preactionspostactions能帮助:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings, patterns}

    \pgfdeclareradialshading{spherebrown}{\pgfpoint{-0.8cm}{1cm}}%
    {rgb(0cm)=(1,1,1);
        rgb(1.5cm)=(0.9059,0.9059,0.5647)
    }
    \pgfdeclareradialshading{spheregreen}{\pgfpoint{-0.8cm}{1cm}}%
    {rgb(0cm)=(0.7980,0.9686,0.9255);
        rgb(1.5cm)=(0.2412,0.3941,0.0392)
    }

\tikzset{
    myblock/.style={
        draw, rectangle, minimum width=30mm, minimum height=10mm,
        line width=.5pt, rounded corners=2pt, gray, text width=28mm,
        font=\bfseries\scriptsize\sffamily, align=center, text=black,
        preaction={shading=spheregreen},
        postaction={pattern=north west lines},
        postaction={draw, shading=spherebrown, transform canvas={xscale=.9, yscale=.8}},
    }
}

\begin{document}

\begin{tikzpicture}
    \node [myblock] {NOSILAC\\DSS AD9833};
\end{tikzpicture}

\end{document}

在此处输入图片描述

为什么不起作用?我理解transform canvas={xscale=..., yscale=...}最后应用postaction来填充“内部矩形”也会改变所应用的坐标系。

答案2

还有一种可能的解决方案,使用:

  • Z 库arrows.meta用于箭头、fit嵌套内部节点、patterns.meta外部节点中的图案、positioning节点定位和shadows节点阴影。
  • 具有样式的节点box由两个节点组成:外部节点具有选定颜色和图案的阴影,内部节点具有黄色阴影并包含组成节点的文本。
  • preaction用于阴影外部节点形状的指令。
  • postaction外部节点绘制图案的说明。
  • postaction绘制外部节点边框的说明。
  • append after command使用库插入内部节点的指令fit
  • 在内部节点指令中label写入节点内容(文本)。

生成的节点样式(根据我的观点)给出了稍微好一点的结果,因为图案不再突出在阳极边界上。其样式定义是:

box/.style args = {#1/#2}{draw, very thin, rounded corners=2pt,
                 minimum height=10mm, text width=28mm,
                 node contents={},
    preaction={upper left=#1!10, lower right=#1!90},
    postaction={pattern={Lines[angle=45,distance={3pt}, line width=0.2pt]}},
    postaction={draw=gray, thick},
    append after command={\pgfextra{\let\LN\tikzlastnode}
        node [draw=gray, thick, rounded corners=2pt,
              upper left=yellow!10, lower right=yellow!90,
              inner sep=-1mm, fit=(\LN),
              label={[align=center, font=\scriptsize\bfseries\sffamily]center:#2},
              ] {} } }      

使用建议的box节点样式的图像示例是:

\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                fit,
                patterns.meta, positioning,
                shadings}

\begin{document}

\begin{tikzpicture}[
  node distance = 1mm and 6mm,
arr/.style      = {-{Straight Barb[scale=0.8]},semithick},
box/.style args = {#1/#2}{draw, very thin, rounded corners=2pt,
                 minimum height=10mm, text width=28mm,
                 node contents={},
    preaction={upper left=#1!10, lower right=#1!90},
    postaction={pattern={Lines[angle=45,distance={3pt}, line width=0.2pt]}},
    postaction={draw=gray, thick},
    append after command={\pgfextra{\let\LN\tikzlastnode}
        node [draw=gray, thick, rounded corners=2pt,
              upper left=yellow!10, lower right=yellow!90,
              inner sep=-1mm, fit=(\LN),
              label={[align=center, font=\scriptsize\bfseries\sffamily]center:#2},
              ] {} } }      
                 ]
\node (n1) [box=teal/NOSILAC\\DSS AD9833];
\node (n2) [below right=of n1,    
            box=brown/BJT\\MODULATOR];
\node (n3) [below  left=of n2,
            box=purple/SIGNAL PORUKE\\DSS AD9833];
\draw[arr]   (n1) -| (n2);
\draw[arr]   (n3) -| (n2);
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容