如何在 Latex 中创建带有数据库和 Web 服务器符号的图形?

如何在 Latex 中创建带有数据库和 Web 服务器符号的图形?

我有一个包含 Web 服务器和数据库符号的图,我想使用 latex 创建它。有没有办法在 latex 中实现它?我刚开始学习,tikz package但我包含了我为实现这个图所做的尝试。图如下:

在此处输入图片描述

我目前为实现该图所做的工作如下:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}

\definecolor{RYB1}{RGB}{218,232,252}
\definecolor{RYB2}{RGB}{245,245,245}


\begin{document}




\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=RYB2]


\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=RYB1]


\tikzstyle{arrow} = [thick,->,>=stealth]


\begin{figure}
\centering
\begin{tikzpicture}[node distance=2cm]


\node (pro1) [process] {Process 1};
\node (dec1) [process, below of=pro1] {Decision 1};
\node (pro2a) [process, below of=dec1, yshift=-0.5cm] {Process 2a};
\node (pro2b) [process, right of=dec1, xshift=2cm, startstop] {Process 2b};
\node (out1) [process, below of=pro2a] {Output};
\node (stop) [process, below of=out1] {Stop};


\draw [arrow] (pro1) -- (dec1);
\draw [arrow] (dec1) -- (pro2a);
\draw [arrow] (dec1) -- (pro2b);

\draw [arrow] (dec1) -- node[anchor=east](pro2a);
\draw [->] (dec1) -- (pro2b);
\draw [<-] (pro2b) --  (dec1);
\draw [arrow]  (pro2a) --  (out1);
\draw [arrow] (out1) --  (stop);


\end{tikzpicture}
\end{figure}


\end{document}

这两个符号的原始来源取自于此在线工具在网络类别中如下图所示: 在此处输入图片描述

谢谢

答案1

对于节点定位,您也可以使用 TikZ 矩阵。

如果你称呼它m,那么你可以将其单元格称为m-row_number-column_number

样式设置请看这里:应该使用 \tikzset 还是 \tikzstyle 来定义 TikZ 样式?

当然,您会将图像放置在example-image-a和 的旁边example-image-b

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{fit, backgrounds, matrix, arrows.meta}
\tikzset{
    startstop/.style={
        rectangle, rounded corners, minimum width=2cm,  
        minimum height=1.5cm,text centered, draw=black, fill=RYB2
    },
    process/.style={
        rectangle, minimum width=2.5cm, minimum height=1cm, text centered, draw=black, fill=RYB1
    },
    arrow/.style={
        blue,-{Stealth[length=6pt]}
    },  
    dasharrow/.style={
        blue, dashed,-{Stealth[length=6pt]}
    }
}

\definecolor{RYB1}{RGB}{218,232,252}
\definecolor{RYB2}{RGB}{245,245,245}

\begin{document}
\begin{figure}\centering
\begin{tikzpicture}[font=\tiny]
    % blocks
    \matrix[matrix of nodes,
        row sep=4ex,
        column sep=5.4em,
        nodes={anchor=center},
        column 2/.style={nodes={process}},
        ] (m) {
        & Text &&[-3em]\\
        |[inner sep=0pt]|\includegraphics[width=2cm]{example-image-a} & Text &&\\[-2ex]
        & Text & |[startstop]| Text & |[inner sep=0pt]|\includegraphics[height=.5cm]{example-image-b} \\[7ex]
        & Text &&\\
        & Text &&\\
    };
    % block background
    \begin{scope}[on background layer]
        \node [draw, fit=(m-1-2)(m-3-2), fill=cyan!5, inner sep=10pt] {};
        \node [draw, fit=(m-4-2)(m-5-2), fill=cyan!5, inner sep=10pt] {};
    \end{scope}    
    % vertical arrows
    \foreach[evaluate=\myblock as \mysucc using int(\myblock+1)] 
        \myblock in {1,2,...,4}
        {\draw[arrow] (m-\myblock-2) -- (m-\mysucc-2);}
    % horizontal arrows
    \coordinate (a) at ([yshift=2ex]m-2-2.west);
    \draw[dasharrow] (a) -- (m-2-1.east|-a) node[midway, above]{Text};
    \coordinate (b) at ([yshift=-2ex]m-2-2.west);
    \draw[dasharrow] (m-2-1.east|-b) -- (b) node[midway, above]{Text};
    \coordinate (c) at ([yshift=2ex]m-3-2.east);
    \draw[dasharrow] (c) -- (m-3-3.west|-c) node[midway, above]{Text};
    \coordinate (d) at ([yshift=-2ex]m-3-2.east);
    \draw[dasharrow] (m-3-3.west|-d) -- (d) node[midway, above]{Text};
    \draw[dasharrow] ([yshift=4ex]m-3-3.east) -| (m-3-4);   
    \draw[dasharrow] (m-3-4) |- ([yshift=-4ex]m-3-3.east);
\end{tikzpicture}
\end{figure}    
\end{document}

在此处输入图片描述

答案2

您可以使用库轻松地将一组节点装箱fit。要将节点彼此相对放置,您应该使用库positioningbelow of=<node>语法实际上没有记录并且有限制)。您可以使用包含简单 的节点嵌入剪贴画\includegraphics

\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{fit,positioning}
\begin{document}

\begin{tikzpicture}[
  process/.style = {draw,fill=blue!20,minimum width=3cm,minimum height=1cm}
  ]

  \node[process]             (n1) {Text};
  \node[process,below=of n1] (n2) {Text};
  \node[process,below=of n2] (n3) {Text};
  \node[draw,fit=(n1) (n2) (n3)] {};

  \node[left=of n2] (l1) {\includegraphics[width=2cm]{example-image-a}};
  \draw[dashed,->] (n2) to[bend left] (l1);
  \draw[dashed,->] (l1) to[bend left] (n2);

  \node[process,right=of n3] (r1) {Text};
  \node[right=of r1] (r2) {\includegraphics[width=2cm]{example-image-b}};
  \draw[dashed,->] (n3) to[bend left] (r1);
  \draw[dashed,->] (r1) to[bend left] (n3);
  \draw[dashed,->] (r1) to[bend left] (r2);
  \draw[dashed,->] (r2) to[bend left] (r1);

  \node[process,below=of n3] (n4) {Text};
  \node[process,below=of n4] (n5) {Text};
  \node[draw,fit=(n4) (n5)] {};

  \draw[->] (n1) -- (n2);
  \draw[->] (n2) -- (n3);
  \draw[->] (n3) -- (n4);
  \draw[->] (n4) -- (n5);

\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容