TikZ 流程图:重叠框

TikZ 流程图:重叠框

我第一次使用 TikZ,正在创建流程图。我想为 LPC、HPC、HPT 和 LPT 插入一些梯形,如下图所示。问题是,如果我简单地用boxcompr替换turb

\tikzset{turb/.style={draw, trapezium, thick, rotate=90, minimum height=1em, minimum width=6em}} %HPT and LPT
\tikzset{compr/.style={draw, trapezium, thick, rotate=-90, minimum height=1em, minimum width=6em}} %LPC and HPC

所有盒子都重叠了。我该如何解决?谢谢。

\documentclass[a4paper,11pt]{article}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{caption}
  \usetikzlibrary{shapes,arrows,fit,calc,positioning}
  \tikzset{box/.style={draw, rectangle, rounded corners, thick, text width=6em, text centered, minimum height=3em}}
  \tikzset{line/.style={draw, thick, -latex'}}
  \tikzset{combustor/.style={draw, ellipse, thick, minimum height=30pt, minimum width=50pt}}
  \tikzset{turb/.style={draw, trapezium, thick, rotate=90, minimum height=1em, minimum width=6em}} %HPT and LPT
  \tikzset{compr/.style={draw, trapezium, thick, rotate=-90, minimum height=1em, minimum width=6em}} %LPC and HPC    



\begin{document}
  \begin{figure}
    \centering
      \begin{tikzpicture}[auto,scale=0.6, every node/.style={scale=0.6}]

        %place nodes
        \node [box] (dev2) {Deviatore 2};
        \node [box, below=0.5cm of dev2] (HPC)       {HPC};
        \node [combustor, right=0.5cm of HPC] (Comb) {Combustore};
        \node [box, right=0.5cm of Comb] (HPT)       {HPT};
        \node [box, right=0.5cm of HPT] (LPT)        {LPT};
        \node [box, right=0.5cm of LPT] (nozzle1)    {Nozzle 1};
        \node [box, left=0.5cm of HPC] (LPC)         {LPC};
        \node [box, below=0.5cm of LPC] (dev1)       {Deviatore 1};
        \node [box, right=0.5cm of dev1] (bypass)    {Bypass};
        \node [box, right=0.5cm of bypass] (nozzle2) {Nozzle 2};
        \node [box, below=0.5cm of dev1] (fan)       {Fan};
        \node [box, below=0.5cm of fan] (diffusore)  {Diffusore};
        %draw path
        \path [line] (diffusore) --       (fan);
        \path [line] (fan)       --       (dev1);
        \path [line] (dev1)      --       (bypass);
        \path [line] (bypass)    --       (nozzle2);
        \path [line] (dev1)      --       (LPC);
        \path [line] (LPC)       --       (HPC);
        \path [line] (HPC)       --       (dev2);
        \path [line] (dev2)      -|       (HPT);
        \path [line] (HPC)       --       (Comb);
        \path [line] (Comb)      --       (HPT);
        \path [line] (HPT)       --       (LPT);
        \path [line] (LPT)       --       (nozzle1);
        \path [line] (dev2)      -|       (LPT);

      \end{tikzpicture}
      \caption{My first flowchart}\label{fig:flowchart}
  \end{figure}
\end{document}

在此处输入图片描述

在此处输入图片描述

答案1

不要使用 ,而要rotate=90使用选项shape border rotate=90(或270取相反数):

在此处输入图片描述

答案2

在您的 MWE 的帮助下,我尝试重现您的草图:

在此处输入图片描述

在其中我使用了 Alenanno 的建议来旋转节点形状并采取了一些其他措施来使代码尽可能紧凑:

  • 对于节点之间的线,box我使用选项 join。它省去了我在那些节点之间画线的时间。
  • 为了消除不存在的行连接线,我reset在节点的前言部分添加了连接选项的定义。使用的是节点“Deviatore 2”。此解决方案取自@user3188445 的答案这里
  • 在节点定位时使用库chains。因此,对于在线的节点,没有必要说left= of >node name>
  • 对于涡轮机和压缩机,定义了通用样式,并指定了其方向的参数
  • 节点之间的距离定义为公共距离node distance=7mm

完整代码为:

\documentclass{article}
%---------------------------------------------------------------%
    \usepackage{tikz}
\usetikzlibrary{arrows,calc,chains,positioning,shapes}
%    \usepackage{caption}
%    \usepackage[margin=25mm,showframe]{geometry}

\makeatletter
\tikzset{reset/.code={\def\tikz@after@path{}}}
\makeatother

    \begin{document}
%    \begin{figure}[htb]
    \centering
\begin{tikzpicture}[
           node distance = 7mm,
every path/.append style = {draw=teal!30!black, very thick},
                    font = \sffamily,
 start chain = going right,
 base/.style = {draw, align=center},
  box/.style = {rectangle, base,
                %rounded corners, on the sketch are not present
                text width=6em, minimum height=3em,
                join=by -latex',on chain},
 comb/.style = {ellipse, base,
                minimum height=30pt, minimum width=50pt,
                on chain},
 turb/.style = {trapezium, base,
                shape border rotate=#1,
                minimum width=4em,
                on chain}, %HPT and LPT
                    ]
%from below to top                    
\node [box] (diff)  {Diffusore};
\node [box, above=of diff] (fan)    {Fan};
%
\node [box,above=of fan] (dev1)     {Deviatore 1};
\node [box] (bypass)                {Bypass};
\node [box] (nozzle2)               {Nozzle 2};
%  
\node [turb=270,above=of dev1] (lpc)    {LPC};
\node [turb=270]    (hpc)               {HPC};
\node [comb]        (Comb)              {Combustore};
\node [turb=90]     (hpt)               {HPT};
\node [turb=90]     (lpt)               {LPT};
\node [box]         (nozzle1)           {Nozzle 1};
%
\node [box,reset, 
       above=of hpc.bottom left corner -| hpc.east]
                    (dev2)              {Deviatore 2};
%
\draw[-latex'] 
    (dev1)      edge (lpc)
    (lpc)       edge (hpc)
    (hpc)       edge (Comb)
    (Comb)      edge (hpt)
    (hpt)       edge (lpt);
\draw[-latex']  (hpc.top left corner) -- (dev2);
\draw[-latex']  (dev2) -| (lpt.bottom right corner);
\draw[-latex']  (dev2) -| (hpt.bottom right corner);
\end{tikzpicture}
%    \caption{My first flowchart}
%\label{fig:flowchart}
%    \end{figure}
    \end{document}

相关内容