框图中的问题

框图中的问题

我有一个关于在 Latex 中制作框图的问题。我的代码生成了一个框图(左侧),但是,我希望连接看起来像示例图(右侧)。该怎么做?

在此处输入图片描述

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,shadows,arrows}
\begin{document}
%\tikzstyle{decision}{line}=[draw,-latex']
\tikzstyle{line}=[draw,-stealth,thick]
\tikzstyle{block}=[draw,rectangle,fill=blue!50, text width=8em, text centered, minimum height=15mm, node distance=10em]

\begin{tikzpicture}
\node [block] (start) {START};
\node [block, below of=start] (end) {END};  
\node [block, left of=end] (another) {ANOTHER};
\node [block, right of=end] (another1) {ANOTHER1};

%arrows
\path [line] (start) -- (end);
\path [line] (start) -| (another);
\path [line] (start) -| (another1);
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案1

start您可以在从到 的路径中间放置一个辅助坐标end

\path [line] (start) -- coordinate[midway] (aux) (end);

然后使用此坐标在该位置弯曲箭头:

\path [line] (start) -- (aux) -| (another);
\path [line] (start) -- (aux) -| (another1);

完整示例:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,shadows,arrows,positioning}

\tikzset{
line/.style={draw,-stealth,thick},
block/.style={draw,rectangle,fill=blue!50, text width=8em, text centered, minimum height=15mm,}
}

\begin{document}

\begin{tikzpicture}
\node [block] (start) {START};
\node [block, below = of start] (end) {END};  
\node [block, left = of end] (another) {ANOTHER};
\node [block, right = of end] (another1) {ANOTHER1};

%arrows
\path [line] (start) -- coordinate[midway] (aux) (end);
\path [line] (start) -- (aux) -| (another);
\path [line] (start) -- (aux) -| (another1);
\end{tikzpicture}

\end{document}

评论

  • 我把旧的\tikzstyle语法改为更方便的\tikzset语法。

  • 我使用定位库将弃用的of=语法更改为更合适的语法。=of

由于你的图是一棵树,强大的forest包(基于 TikZ 构建)可能会引起您的兴趣;这是使用森林的相同图表:

\documentclass{article}
\usepackage{forest}
\usetikzlibrary{shapes,shadows,arrows,positioning}

\tikzset{
line/.style={draw,-stealth,thick},
block/.style={draw,rectangle,fill=blue!50, text width=8em, text centered, minimum height=15mm,}
}

\begin{document}

\begin{forest}
for tree={
  block,
  parent anchor=south,
  child anchor=north,
  l sep=20pt,
  edge path={
    \noexpand\path[\forestoption{edge}]
      (!u.parent anchor) -- +(0,-10pt) -|   
      (.child anchor)\forestoption{edge label};
  },
  edge={->,>=latex}
} 
[START
  [ANOTHER
  ]
  [END
  ]
  [ANOTHER1
  ]
]
\end{forest}

\end{document}

在此处输入图片描述

相关内容