具有自定义形状的 Tikz 复杂流程图

具有自定义形状的 Tikz 复杂流程图

我正在尝试使用 Tikz 重新创建下面的“流程图”。我能够创建各种形状,但遇到了几个问题:

  1. 页面应该以横向显示,但是该包裹pdflscape破坏了整个图形。
  2. 每个元素应等距分布,就像一个网格。
  3. 我不知道如何让它轻松调整,比如一次控制所有矩形的大小以及“ ”circle中的大小。spenode
  4. 另一个重要的事情是箭头连接。我想要角度而不是直线。
  5. 我怎样才能将四个圆圈放置在边框上,以便当我调整它时它们会自动跟随?

在此处输入图片描述

梅威瑟:

\documentclass[headinclude]{scrbook}
\usepackage[left=32.5mm, right=25mm, top=25mm, bottom=20mm, showframe]{geometry}
\usepackage[font={small}]{caption}
\usepackage{tikz}
    \usetikzlibrary{calc}
    \usetikzlibrary{tikzmark}
    \tikzset{>=stealth}
\usepackage{tikzpagenodes}
\usepackage{pdflscape}

\begin{document}

% \begin{landscape}
\begin{figure}
    \newcommand{\zustand}[1]{%
        \begin{scope}[rotate=90, transform shape]
            \node[circle, draw, fill=white, minimum size=0.7cm, above, label={[align=center, fill=white]above:{#1}}] at (1,1) {};
        \end{scope}%
    }
    \centering\small
    \begin{tikzpicture}[remember picture]
        \draw[ultra thick] ($(current page text area.north west)+(0.8pt,-1cm)$) rectangle ($(current page text area.south east) + (-0.8pt,1cm) $);
        \zustand{test\\test long};

        \node[rectangle, draw, minimum width=1.5cm, minimum height=0.75cm, rotate=90] (lei) {};
        \draw (lei.west) -- (lei.east);

        \node[rectangle, draw, minimum width=1.5cm, minimum height=0.75cm, rotate=90] (wan) at (2,14) {};
        \draw (wan.north west) -- (wan.east) -- (wan.south west);

        \node[rectangle, draw, minimum width=1.5cm, minimum height=0.75cm, rotate=90] (spe) at (2,2) {};
        \draw (spe.center) circle (0.375cm);

        \node[rectangle, draw, minimum width=1.5cm, minimum height=0.75cm, rotate=90] (ver) at (1,1) {};
        \draw (ver.north west) -- (ver.center) -- (ver.south west);
        \draw (ver.center) -- (ver.east);

        \draw[->, dotted] (ver.east) -- (wan.west);
    \end{tikzpicture}
    \caption{Test}
\end{figure}
% \end{landscape}

\end{document}

答案1

这不是一个答案,而是一个一些评论,我希望可以帮助OP轻松绘制他的方案。

首先,我定义了一些.styles来绘制每个不同的元素。它们都基于一个basic固定尺寸的节点,而特定的样式只定义内部path picture。这解决了问题 3。

节点定位通过(问题 2)解决positioning library。图片有一个默认值node distance,以节省一些输入,但这可以在每个新节点中特别更改。此距离也可以在 内使用,chain正如 BambOo 在之前的评论中所建议的那样。如果节点分布更规则,另一个解决方案可能是matrix

下面的例子显示了角落连接(问题 4),但我不确定这是否是这个问题的意思。

关于第五个问题,我认为一旦绘制好所有方案,就可以轻松定义边框。这比尝试将绘图调整为固定边框要好。

\documentclass[headinclude]{scrbook}
\usepackage[left=32.5mm, right=25mm, top=25mm, bottom=20mm, showframe]{geometry}
\usepackage[font={small}]{caption}
\usepackage{tikz}
    \usetikzlibrary{calc, positioning, fit, backgrounds}
    \usetikzlibrary{tikzmark}
    \tikzset{>=stealth}
\usepackage{tikzpagenodes}
\usepackage{pdflscape}

\tikzset{
    zustand/.style={circle, draw, fill=white, minimum size=0.7cm,
        label={[align=center, fill=white]{#1}}},
    basic/.style={rectangle, draw, minimum width=1.5cm, minimum height=0.75cm},
    lei/.style={basic,
        path picture={\draw (path picture bounding box.west)--(path picture bounding box.east);}},
    wan/.style={basic,
        path picture={\draw (path picture bounding box.north west)--(path picture bounding box.east)--(path picture bounding box.south west);}},
    ver/.style={basic,
        path picture={\draw (path picture bounding box.north west)--(path picture bounding box.center)--(path picture bounding box.south west); \draw(path picture bounding box.center)--(path picture bounding box.east);}},
    spe/.style={basic,
        path picture={\draw (path picture bounding box.center) let \p1=($ (path picture bounding box.north)-(path picture bounding box.south)$) in circle({veclen(\x1,\y1)/2});}},
}
\begin{document}

\begin{figure}
    \centering\small
    \begin{tikzpicture}[node distance = 1cm and 2cm,
        line/.style={->, dotted}]
        \node[zustand={test\\test long}] (zustand-a) {};

        \node[lei, right=of zustand-a] (lei-a) {};

        \node[wan, above right=of lei-a] (wan-a) {};

        \node[spe, below=of wan-a] (spe-a) {};

        \node[ver, below left=of spe-a] (ver-a) {};

        \node[zustand={test\\test long}, left=of ver-a.south west] (zustand-b) {};

        \node[zustand={test\\test long}, right=of wan-a] (zustand-c) {};


        \draw[line] (zustand-a) -- (lei-a);
        \draw[line] (lei-a.east) -- ++(0:5mm)|-(wan-a);
        \draw[line] (wan-a.east) --++(5mm,0)|- (spe-a);
        \draw[line] (spe-a.south west)--++(180:5mm)|-(ver-a.south east);
        \draw[line] (ver-a.south west)--(zustand-b);

        \draw[line, thick] (spe-a.south east)-|++(1,-0.5)-|([xshift=-5mm]ver-a.north west)--(ver-a.north west);

        \begin{scope}[on background layer]
        \node[fit={([yshift=-5mm]zustand-b.south) ([yshift=3cm]zustand-c.north)}, inner sep=0pt, draw, thick] {};
        \end{scope}
    \end{tikzpicture}
    \caption{Test}
\end{figure}

\end{document}

在此处输入图片描述

相关内容