我有下面的流程图,想要一个像上面添加的绿色箭头一样的箭头,上面写着条件(但当然是与其他箭头相同的灰色)
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,shadows}
\usetikzlibrary{shapes,arrows}
\begin{document}
\pagestyle{empty}
% Define block styles
\tikzstyle{big} = [rectangle, draw, fill=blue!20,
text width=30em, text centered, rounded corners, minimum height=4em]
\tikzstyle{small} = [rectangle, draw, fill=blue!20,
text width=14em, text centered, rounded corners, minimum height=4em]
\begin{figure}[!ht]
\centering
\quad
\begin{tikzpicture}[align = center, node distance = 2.5cm, auto, >=latex, %Make the arrow tips latex
myline/.style={ultra thick,black!50},
shorter/.style={shorten <=1mm,shorten >=0.5mm}]
% nodes
\node [big] (A) {Blabla};
\node[big, below of = A] (B) {Blabla};
\node[big, below of = B] (C) {Blabla};
\node[small, below=2.5cm of C.west, anchor=west] (Da) {Blabla};
\node[small, below=3.7cm of C.east, anchor=east] (Ea) {Blabla};
\node[small, below of = Da] (Db) {Blabla};
\node[big, below = 2.5cm of Db.west, anchor=west] (F) {Blabla};
\node[big, below of = F] (G) {Blabla};
\node[big, below of = G] (H) {Blabla};
\node[big, below of = H] (I) {Blabla};
% Edges
\draw[myline,->, shorter] (A) -- (B);
\draw[myline,->, shorter] (B) -- (C);
\draw[myline,->, shorter] ([xshift=2.6cm]C.south west) -- (Da);
\draw[myline,->, shorter] (Da) -- (Db);
\draw[myline,->, shorter] ([xshift=8.2cm]C.south west) -- (Ea);
\draw[myline,->, shorter] ([xshift=2.6cm]Db.south west) ++(0,0) -- ++(0,-0.5) -| (F);
\draw[myline,->, shorter] ([xshift=2.6cm]Ea.south west) ++(0,0) -- ++(0,-1.8) -| (F);
\draw[myline,->, shorter] (F) -- (G);
\draw[myline,->, shorter] (G) -- (H);
\draw[myline,->, shorter] (H) -- (I);
\end{tikzpicture}
\end{figure}
\end{document}
答案1
你想要的箭头可能是这样的:
\draw[myline,->, shorter] (I) --++(-90:15mm)-|([xshift=10mm]G.east) node[pos=.25,above]{some text}--(G);
意思是,从(但从相应的边界开始)绘制到低于(方向度)(I.center)
的一点,并将笔移动到该点( )。然后从该点到另一个点绘制一个角( ) ,最后结束于(尊重相应的边界)。15mm
-90
++
-|
([xshift=10mm]G.east)
(G.center)
文本以 位于水平线上pos=0.25
,因为使用或pos=0.5
时总是与角相对应。|-
-|
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,shadows}
\usetikzlibrary{shapes,arrows}
\begin{document}
%\pagestyle{empty}
% Define block styles
\tikzstyle{big} = [rectangle, draw, fill=blue!20,
text width=30em, text centered, rounded corners, minimum height=4em]
\tikzstyle{small} = [rectangle, draw, fill=blue!20,
text width=14em, text centered, rounded corners, minimum height=4em]
%\begin{figure}[!ht]
% \centering
% \quad
\begin{tikzpicture}[align = center, node distance = 2.5cm, auto, >=latex, %Make the arrow tips latex
myline/.style={ultra thick,black!50},
shorter/.style={shorten <=1mm,shorten >=0.5mm}]
% nodes
\node [big] (A) {Blabla};
\node[big, below of = A] (B) {Blabla};
\node[big, below of = B] (C) {Blabla};
\node[small, below=2.5cm of C.west, anchor=west] (Da) {Blabla};
\node[small, below=3.7cm of C.east, anchor=east] (Ea) {Blabla};
\node[small, below of = Da] (Db) {Blabla};
\node[big, below = 2.5cm of Db.west, anchor=west] (F) {Blabla};
\node[big, below of = F] (G) {Blabla};
\node[big, below of = G] (H) {Blabla};
\node[big, below of = H] (I) {Blabla};
% Edges
\draw[myline,->, shorter] (A) -- (B);
\draw[myline,->, shorter] (B) -- (C);
\draw[myline,->, shorter] ([xshift=2.6cm]C.south west) -- (Da);
\draw[myline,->, shorter] (Da) -- (Db);
\draw[myline,->, shorter] ([xshift=8.2cm]C.south west) -- (Ea);
\draw[myline,->, shorter] ([xshift=2.6cm]Db.south west) ++(0,0) -- ++(0,-0.5) -| (F);
\draw[myline,->, shorter] ([xshift=2.6cm]Ea.south west) ++(0,0) -- ++(0,-1.8) -| (F);
\draw[myline,->, shorter] (F) -- (G);
\draw[myline,->, shorter] (G) -- (H);
\draw[myline,->, shorter] (H) -- (I);
\draw[myline,->, shorter] (I) --++(-90:15mm)-|([xshift=10mm]G.east) node[pos=.25,above]{some text}--(G);
\end{tikzpicture}
%\end{figure}
\end{document}
答案2
使用node[pos=xx]{}
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\node[draw] (node1) at (0,0){node 1};
\node[draw] (node2) at (0,-5){node 2};
\draw[-latex] (node2.south) |-
node[pos=0.75,above]{text 1}
($(node2.south east)+(2,-1)$) |-
node[pos=0.25,right]{text 2}
node[pos=0.75,below]{text 3}
(node1.east)
;
\end{tikzpicture}
\end{document}
答案3
循环的解决方案类似于答案中给出的解决方案帕帕和伊格纳西,但整个图表是以更复杂的方式绘制的:
- 常见节点特征以样式形式收集
base
- 较大的节点在链上并通过宏连接
join
- 较小的节点通过库的帮助进行定位
positioning
- 增加了新的命令
suppress join
,用于断开第一部分和第二部分大节点之间的连接
完成 MWE:
\documentclass[tikz, border=5mm]{standalone}
\usetikzlibrary{arrows.meta, calc, chains, positioning}
\makeatletter
\tikzset{suppress join/.code={\def\tikz@after@path{}}}
\makeatother
\begin{document}
\begin{tikzpicture}[
node distance = 11mm and 0mm,
start chain = going below,
every path/.style = {draw=black!50, ultra thick,
shorten <=1mm,shorten >=0.5mm,
-Latex},
base/.style = {rectangle, draw, fill=blue!20, rounded corners,
minimum height=4em, align=center},
big/.style = {base, text width=30em, on chain, join},
small/.style = {base, text width=14em},
]
% nodes
\node[big] (A) {Blabla};
\node[big] (B) {Blabla};
\node[big] (C) {Blabla};
%
\node[small, below right=of C.south west] (Da) {Blabla};
\node[small, below=of Da] (Db) {Blabla};
\node[small, right=2em of $(Da.east)!0.5!(Db.east)$] (E) {Blabla};
%
\node[big, suppress join,
below = of Db.south -| C] (F) {Blabla Blabla};
\node[big] (G) {Blabla};
\node[big] (H) {Blabla};
\node[big] (I) {Blabla};
% Edges
\draw (C.south -| Da) edge (Da) (Da) edge (Db)
(C.south -| E) edge (E) (F) -- (G);
%
\draw (Db) |- ([yshift=7mm] F.north) coordinate (Fa) -- (F);
\draw (E) |- (Fa) -- (F);
%
\draw[red] (I.south) -- ++(0,-11mm)
-| ($(I.east)+(11mm,0)$) node[pos=0.25,above] {add text here}
|- (F);
\end{tikzpicture}
\end{document}