编辑

编辑

我正在学习 tiKz 包以便在 LaTex 中绘制图表等,但我必须绘制一个对我来说相当困难的架构。

我需要绘制下图中的架构,此外,还要绘制对齐的模块。有人能帮我吗?

在此处输入图片描述

答案1

可能需要一些工作并且可能不适合您现有的方法,但这样的方法可能会有效:

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{positioning,fit,shapes.arrows,shadows}
\newcounter{module}
\setcounter{module}{0}
\renewcommand*\themodule{\Alph{module}}
\tikzset{%
  module/.style={rounded corners, align=center, font=\sffamily, thick},
  simple module/.style={module, top color=blue!10, bottom color=blue!35, draw=blue!75, text width=40mm, minimum height=15mm, drop shadow},
  square module/.style={module, draw=orange!75!black, minimum height=20mm, text width=20mm},
  long module/.style={module, draw=orange!75!black, minimum height=20mm, text width=50mm},
  combo module/.style={module, draw=blue!75!black},
  simple module/.pic={
    \stepcounter{module}
    \node (module \themodule) [simple module] {Module \themodule};
  },
  module down arrow/.style={module arrow, shape border rotate=-90, yshift=1.25mm},
  module right arrow/.style={module arrow, xshift=-1.25mm},
  pics/horizontal module/.style n args=2{
    code={
      \stepcounter{module}
      \coordinate (c) at (0,0);
      \node [module right arrow] at (c) {};
      \node (module \themodule-1) [square module, left=7.5mm of c] {#1};
      \node (module \themodule-2) [square module, right=7.5mm of c] {#2};
      \node (module \themodule-3) [below=1.5mm of c |- module \themodule-2.south, module] {Module \themodule};
      \node (module \themodule) [fit=(module \themodule-1) (module \themodule-2) (module \themodule-3), combo module] {};
    }
  },
  pics/vertical module/.style n args=2{
    code={
      \stepcounter{module}
      \coordinate (c) at (0,0);
      \node [module down arrow] at (c) {};
      \node (module \themodule-1) [long module, above=7.5mm of c] {#1};
      \node (module \themodule-2) [long module, below=7.5mm of c] {#2};
      \node (module \themodule-3) [above=1.5mm of module \themodule-1.north, module] {Module \themodule};
      \node (module \themodule) [fit=(module \themodule-1) (module \themodule-2) (module \themodule-3), combo module] {};
    }
  },
  module arrow/.style={single arrow, single arrow head extend=2.5mm, drop shadow, draw=gray!75, inner color=gray!20, outer color=gray!35, thick, shape border uses incircle, text height=1.5mm, text width=2.5mm, anchor=center},
}
\begin{document}
\begin{tikzpicture}
  \pic {simple module};
  \node [module down arrow] at ([yshift=-7.5mm]module A.south) {};
  \pic [below=27.5mm of module A.south] {horizontal module={Description 1}{Description 2}};
  \node [module right arrow] at ([xshift=7.5mm]module B.east) {};
  \pic [right=42.5mm of module B.east] {vertical module={Description 3}{Description 4}};
  \node [module down arrow] at ([yshift=-7.5mm]module C.south) {};
  \pic [below=27.5mm of module C.south] {horizontal module={Description 5}{Description 6}};
  \node [module down arrow] at ([yshift=-7.5mm]module D.south) {};
  \pic [below=17.5mm of module D.south] {simple module};
\end{tikzpicture}
\end{document}

模块和箭头

编辑

此版本增加了一点深度,并尝试简化放置:

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{positioning,fit,shapes.arrows,shadows,backgrounds}
\newcounter{module}
\setcounter{module}{0}
\renewcommand*\themodule{\Alph{module}}
\tikzset{%
  module/.style={rounded corners, align=center, font=\sffamily, thick, fill=white},
  simple module/.style={module, top color=blue!10, bottom color=blue!35, draw=blue!75, text width=40mm, minimum height=15mm, drop shadow},
  square module/.style={module, draw=orange!75!black, inner color=white, outer color=orange!75!black!5, minimum height=20mm, text width=20mm},
  long module/.style={module, draw=orange!75!black, inner color=white, outer color=orange!75!black!5, minimum height=20mm, text width=50mm},
  combo module/.style={module, draw=blue!75!black, inner color=white, outer color=blue!75!black!5, drop shadow},
  simple module/.pic={
    \stepcounter{module}
    \node (module \themodule) [simple module] {Module \themodule};
  },
  module down arrow/.style={module arrow, shape border rotate=-90, yshift=1.25mm, anchor=north},
  module right arrow/.style={module arrow, xshift=-1.25mm, anchor=west},
  pics/horizontal module/.style n args=2{
    code={
      \stepcounter{module}
      \coordinate (c) at (0,0);
      \node (arrow \themodule-1) [module right arrow, anchor=center] at (c) {};
      \node (module \themodule-1) [square module, left=2.5mm of arrow \themodule-1.west] {#1};
      \node (module \themodule-2) [square module, right=2.5mm of arrow \themodule-1.tip] {#2};
      \node (module \themodule-3) [below=1.5mm of c |- module \themodule-2.south, module] {Module \themodule};
      \scoped[on background layer]{\node (module \themodule) [fit=(module \themodule-1) (module \themodule-2) (module \themodule-3), combo module] {};}
    }
  },
  pics/vertical module/.style n args=2{
    code={
      \stepcounter{module}
      \coordinate (c) at (0,0);
      \node (arrow \themodule-1) [module down arrow] at (c) {};
      \node (module \themodule-1) [long module, above=2.5mm of arrow \themodule-1.north] {#1};
      \node (module \themodule-2) [long module, below=2.5mm of arrow \themodule-1.tip] {#2};
      \node (module \themodule-3) [above=1.5mm of module \themodule-1.north, module] {Module \themodule};
      \scoped[on background layer]{\node (module \themodule) [fit=(module \themodule-1) (module \themodule-2) (module \themodule-3), combo module] {};}
    }
  },
  module arrow/.style={single arrow, single arrow head extend=2.5mm, drop shadow, draw=gray!75, inner color=gray!20, outer color=gray!35, thick, shape border uses incircle, text height=1.5mm, text width=2.5mm, anchor=center},
}
\begin{document}
\begin{tikzpicture}
  \pic {simple module};
  \node (arrow AB) [module down arrow, below=5mm of module A] {};
  \pic [below=15mm of arrow AB.tip] {horizontal module={Description 1}{Description 2}};
  \node (arrow BC)  [module right arrow, right=5mm of module B] {};
  \pic [right=30mm of arrow BC.tip] {vertical module={Description 3}{Description 4}};
  \node (arrow CD) [module down arrow, below=5mm of module C] {};
  \pic [below=15mm of arrow CD.tip] {horizontal module={Description 5}{Description 6}};
  \node (arrow DE) [module down arrow, below=5mm of module D] {};
  \pic [below=5mm of arrow DE.tip] {simple module};
\end{tikzpicture}
\end{document}

模块和箭头

答案2

matrix方法可能存在一些局限性,但它使得建立类似的结构变得非常简单。

我厚颜无耻地借用并改编了 cfr 答案中的一些样式。箭头是使用几个循环添加的,这样更容易集体微调位置。

在此处输入图片描述

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,matrix,shapes.arrows}

\tikzset{
  modulematrix/.style={draw=blue!50!red,rounded corners,matrix of nodes,row sep=1cm,column sep=1cm,nodes={draw=green!70,align=center,font=\sffamily},inner ysep=0.5cm},
  module/.style={rounded corners, align=center, font=\sffamily, thick},
  simple module/.style={module, top color=blue!10, bottom color=blue!35, draw=blue!75, text width=40mm, minimum height=15mm},
  module down arrow/.style={module arrow, shape border rotate=-90},
  module right arrow/.style={module arrow},
module arrow/.style={single arrow, single arrow head extend=2.5mm, draw=gray!75, inner color=gray!20, outer color=gray!35, thick, shape border uses incircle, anchor=tail,minimum height=0.7cm},
}
\begin{document}
\begin{tikzpicture}
\node [simple module] (mA) {Module A};
\matrix[modulematrix,below=of mA,label={[anchor=south]below:Module B}] (mB) {Description 1 & Description 2 \\};
\matrix[modulematrix,right=of mB,nodes={text width=5cm,align=center},label={[anchor=north]above:Module C}] (mC) {Description 3 \\ Description 4 \\};
\matrix[modulematrix,below=of mC,label={[anchor=south]below:Module D}] (mD) {Description 5 & Description 6 \\};
\node [simple module,below=of mD] (mE) {Module E};

\foreach \n in {mA,mC-1-1,mC,mD}
  \node[module down arrow,below=1mm of \n] {};

\foreach \n in {mB-1-1,mB,mD-1-1}
  \node[module right arrow,right=1mm of \n] {};
\end{tikzpicture}
\end{document}

答案3

以下是使用保存框的方法。我还偷了 cfr 的箭头样式。

请注意,当您旋转箭头时,它也会旋转锚点(北、东……)。

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,shapes.arrows}

\tikzset{big arrow/.style={single arrow, single arrow head extend=2.5mm,
  draw=gray!75, inner color=gray!20, outer color=gray!35, thick,
  shape border uses incircle, minimum height=0.7cm,outer sep=2mm}}

\newsavebox{\boxa}
\newsavebox{\boxb}
\newsavebox{\boxc}
\newsavebox{\boxd}

\begin{document}

\savebox{\boxa}{%
\begin{tikzpicture}
  \node (A) {Label 1};
  \node[big arrow,rotate=-90,below right] at (A.north west) {};
  \node[big arrow,rotate=-90,above right] at (A.north east) {};
\end{tikzpicture}}

\savebox{\boxb}{%
\begin{tikzpicture}[font=\tiny]
  \node (A) [draw=orange,rounded corners,minimum height=2cm, minimum width=2cm] {Description 1};
  \node (B) [big arrow,right] at (A.east) {};
  \node[draw=orange,rounded corners,minimum height=2cm, minimum width=2cm,right] at (B.east) {Description 2};
  \node[below] at (A.south) {\normalsize Module B};
\end{tikzpicture}}

\savebox{\boxc}{%
\begin{tikzpicture}[font=\tiny]
  \node (A) [draw=orange,rounded corners,minimum height=1.5cm, minimum width=4cm] (A) {Description 3};
  \node (B) [big arrow,rotate=-90,right] at (A.south) {};
  \node[draw=orange,rounded corners,minimum height=1.5cm, minimum width=4cm,below] at (B.east) {Description 4};
  \node[above] at (A.north) {\normalsize Module C};
\end{tikzpicture}}

\savebox{\boxd}{%
\begin{tikzpicture}[font=\tiny]
  \node (A) [draw=orange,rounded corners,minimum height=2cm, minimum width=2cm] {Description 5};
  \node (B) [draw=orange,rounded corners,minimum height=2cm, minimum width=2cm,right=1cm] at (A.east) {Description 6};
  \node[above] at ($(A.north)!.5!(B.north)$) {\normalsize Module C};
\end{tikzpicture}}

\begin{tikzpicture}
\node (A) [draw=blue,fill=blue!20,rounded corners,minimum height=2cm,minimum width=4cm] {Module A};
\node (B) [below] at (A.south) {\usebox{\boxa}};
\node (C) [draw=blue,rounded corners,below] at (B.south) {\usebox{\boxb}};
\node (D) [big arrow,right] at (C.east){};
\node (E) [draw=blue,rounded corners,right] at (D.east) {\usebox{\boxc}};
\node (F) [big arrow,rotate=-90,right] at (E.south) {};
\node (G) [draw=blue,rounded corners,below] at (F.east) {\usebox{\boxd}};
\node (H) [big arrow,rotate=-90,right] at (G.south) {};
\node (I) [draw=blue,fill=blue!20,rounded corners,minimum height=2cm,minimum width=4cm,below] at (H.east) {Module D};
\end{tikzpicture}
\end{document}

tikzpicture 带有保存框

相关内容