如何在 Tikz 工作流程图中创建具有 2 个连续 90 度角的线?

如何在 Tikz 工作流程图中创建具有 2 个连续 90 度角的线?

我在尝试将决策节点与第二个流程节点连接时遇到了一些问题。具体来说,我希望有一条水平线,后面跟着一条垂直线和另一条水平线 (- | -)。

此外,我想根据工作流的中心轴将工作流居中。相反,Latex 会同时考虑侧箭头,将它们居中。有什么建议吗?

非常感谢能够回答的人。

\begin{tikzpicture}[node distance=2.7cm]
    \node(pro1) [forno]{Trattamenti Termici};
    \node(pro2) [process, below of=pro1]{Lavorazioni Meccaniche};
    \node(dec) [decision, below of=pro2, text width=4cm, yshift=-1.5cm]{Il ciclo prevede ulteriori fasi di TT?};
    \node(stop) [startstop, below of=dec,  yshift=-1.8cm]{M10};
    \node[
    draw,
    densely dotted,
    red,
    inner sep=8pt,
    fit={(pro2) (stop)},
    ] (fit) {};
    \node[above right, inner sep=0pt] at (fit.north west) {UME Nord};
    
    \draw[arrow] (pro1) -- (pro2);
    \draw[arrow] (pro2) -- (dec);
    \draw[dashed, ->] (dec) -- ++ (3cm,0) node[anchor=east] [above,pos=0.25]{Sì} (pro1);
    \draw [dashed, ->] (dec) -| (pro2);
    \draw[arrow] (dec) --  node[anchor=south] [left,pos=0.25]{No} (stop);
\end{tikzpicture}

工作流程中从 (dec) 到 (pro2) 的虚线箭头不正确

答案1

  • 请始终提供 MWE(最小工作示例),以便我们可以按原样测试您的文档示例(类似于下面的 MWE)
  • 不太清楚反馈回路应该放在哪里。我猜如下图所示。
  • 我提出两个建议。第一个是“经典”,第二个则更“花哨”(正如@Qrrbrbirlbel 在他的一个回答中所建议的那样):

在此处输入图片描述

\documentclass[margin=3mm, varwidth=66mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{chains,
                ext.paths.ortho,    % -|- and |-| path operations
                fit,
                positioning,
                quotes,
                shapes.geometric}

\begin{document}
    \begin{tikzpicture}[
   node distance = 8mm and 12mm,
     start chain = A going below,
     base/.style = {draw, fill=#1,
                    text width=32mm, minimum height=7mm,
                    align=center},
startstop/.style = {base=red!30, rounded corners},
  process/.style = {base=orange!30},
       io/.style = {base=blue!30,
                    trapezium, trapezium stretches body,
                    trapezium left angle=70, trapezium right angle=110},
 decision/.style = {base=green!30, diamond, aspect=1.7, inner xsep=-3pt},
      FIT/.style = {draw=red, densely dotted, inner xsep=8mm,
                    fit=#1},
       lb/.style = {label={[lbl, anchor=north west]south:#1}},
       ll/.style = {label={[lbl, anchor=south east]west:#1}},
      arr/.style = {semithick,-latex},
                        ]
    \begin{scope}[nodes={on chain, join=by arr}]
\node   [process]   {Trattamenti Termici};
\node   [process]   {Lavorazioni Meccaniche};
\node   [decision]  {Il ciclo prevede ulteriori fasi di TT?};
\node   [startstop] {M10};
    \end{scope}

\node[FIT={(A-2) (A-4)},
      label={[anchor=south west]north west:UME Nord}] (f1) {};

\draw[arr,dashed]  (A-3.east) -|-[distance=-20mm] (A-2.east) % feedback loop
                    node[pos=0.1, above] {Sì};
\path (A-3) to ["No"] (A-4);
    \end{tikzpicture}

\bigskip
or a bit more fancy
\bigskip

    \begin{tikzpicture}[
   node distance = 8mm and 12mm,
     start chain = A going below,
     base/.style = {draw, fill=#1,
                    text width=32mm, minimum height=7mm,
                    align=center,
                    on chain=A},
startstop/.style = {base=red!30, rounded corners},
  process/.style = {base=orange!30},
       io/.style = {base=blue!30,
                    trapezium, trapezium stretches body,
                    trapezium left angle=70, trapezium right angle=110},
       if/.style = {base=teal!30, align=left, align=flush center,
                    label={[D=teal]north east:}},
            D/.style = {diamond, draw=#1, fill=#1!60, inner sep=1.6mm,
                        anchor=center},
          lbl/.style = {inner sep=3pt, font=\small, text=black!75},
       lb/.style = {label={[lbl, anchor=north west]south:#1}},
       ll/.style = {label={[lbl, anchor=south east]west:#1}},
       lr/.style = {label={[lbl, xshift=2mm, anchor=south west]east:#1}},
      FIT/.style = {draw=red, densely dotted,
                    inner xsep=6mm, inner ysep=2mm,
                    fit=#1},
      arr/.style = {semithick,-latex}
                        ]
    \begin{scope}[nodes={join=by arr}]
\node   [process]   {Trattamenti Termici};
\node   [process]   {Lavorazioni Meccaniche};
\node   [if,
         lb=Si,
         lr=No]     {Il ciclo prevede ulteriori fasi di TT?};
\node   [startstop] {M10};
    \end{scope}
\node[FIT={(A-2) (A-4)}] (f1) {};
\node[above right] at (f1.north west) {UME Nord};

\draw[arr,densely dashed]  (A-3.east) -|-[distance=10mm] (A-2.east); % feedback loop
    \end{tikzpicture}
\end{document}

附录:
甚至更加“经典”......无需使用库ext.paths.ortho,

\documentclass[margin=3mm, varwidth=66mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{chains, 
                fit,
                positioning,
                quotes,
                shapes.geometric}

\begin{document}
    \begin{tikzpicture}[
   node distance = 8mm and 12mm,
     start chain = A going below,
     base/.style = {draw, fill=#1,
                    text width=32mm, minimum height=7mm,
                    align=center},
startstop/.style = {base=red!30, rounded corners},
  process/.style = {base=orange!30},
       io/.style = {base=blue!30,
                    trapezium, trapezium stretches body,
                    trapezium left angle=70, trapezium right angle=110},
 decision/.style = {base=green!30, diamond, aspect=1.7, inner xsep=-3pt},
      FIT/.style = {draw=red, densely dotted, inner xsep=8mm,
                    fit=#1},
       lb/.style = {label={[lbl, anchor=north west]south:#1}},
       ll/.style = {label={[lbl, anchor=south east]west:#1}},
      arr/.style = {semithick,-latex},
                        ]
    \begin{scope}[nodes={on chain, join=by arr}]
\node   [process]   {Trattamenti Termici};
\node   [process]   {Lavorazioni Meccaniche};
\node   [decision]  {Il ciclo prevede ulteriori fasi di TT?};
\node   [startstop] {M10};
    \end{scope}

\node[FIT={(A-2) (A-4)},
      label={[anchor=south west]north west:UME Nord}] (f1) {};
\draw[arr,dashed]  (A-3.east) to["Si"] ++ (1,0) |- (A-2); % feedback loop
\path (A-3) to ["No"] (A-4);
    \end{tikzpicture}
\end{document}

结果与上面的第一张图像非常相似。

相关内容