如何添加这一行?
当前代码:
\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage{fp, tikz}
\usetikzlibrary{arrows,shapes,backgrounds,patterns,fadings,matrix,arrows,calc,
intersections,decorations.markings,
positioning,external,arrows.meta}
\tikzset{
block/.style = {draw, rectangle,
minimum height=1cm,
minimum width=2cm},
input/.style = {coordinate,node distance=1cm},
output/.style = {coordinate,node distance=6cm},
arrow/.style={draw, -latex,node distance=2cm},
pinstyle/.style = {pin edge={latex-, black,node distance=2cm}},
sum/.style = {draw, circle, node distance=1cm},
}
\begin{document}
\begin{tikzpicture}[auto, >=latex', transform shape,font={\sffamily \small}]
\node [draw=black,
minimum width=1.6cm,
minimum height=1.2cm,
align=center] (1) {1};
\node [draw=black,
minimum width=1.6cm,
minimum height=1.2cm,
align=center,
right=0.6cm of 1] (2) {2};
\node [draw=black,
minimum width=1.6cm,
minimum height=1.2cm,
align=center,
right=0.6cm of 2] (3) {3};
\draw[->,line width=0.25mm] (1.east) -- (2.west);
\draw[->,line width=0.25mm] (2.east) -- (3.west);
\end{tikzpicture}
\end{document}
答案1
由于您加载了计算库,您可以使用它的功能来查找两个节点之间的中点。您可以在代码后添加以下行。
\draw[->,line width=0.25mm] ($(1)!0.5!(2)$) --++ (0,1.3cm) -| (3.north);
第一个坐标($(1)!0.5!(2)$)评估节点 (1) 和 (2) 之间的中点。
第二个坐标 --++ (0,1.3cm) 是我创建的虚拟点,用于将箭头抬高到节点上方。您可以根据需要调整 1.3cm。
答案2
(1)
您可以在从到的线段上设置一个坐标,(2)
就像一个节点一样。线的中点是默认值。然后您可以从那里绘制新箭头。
另外,我还大大简化了你的代码。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning, arrows}
\tikzset{
block/.style = {draw, rectangle, minimum height=1.2cm, minimum width=1.6cm}
}
\begin{document}
\begin{tikzpicture}[>=latex',font={\sffamily\small}, node distance=.6cm]
\node [block] (1) {1};
\node [block, right=of 1] (2) {2};
\node [block, right=of 2] (3) {3};
\draw[->,line width=0.25mm] (1.east) --coordinate(M) (2.west);
\draw[->,line width=0.25mm] (2.east) -- (3.west);
\draw[->,line width=0.25mm] (M) --++ (0,1) -| (3);
\end{tikzpicture}
\end{document}
答案3
通过使用该ext.paths.ortho
库,真正的 MWE(最小工作示例)专注于您的问题:
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
chains,
ext.paths.ortho, % defined in the tikz-ext package
positioning,
}
\begin{document}
\begin{tikzpicture}[
node distance = 4mm and 6mm,
start chain = going right,
arr/.style = {-{Straight Barb[scale=0.8]}, semithick},
box/.style = {% default is rectangle
draw, minimum height = 10mm, minimum width=20mm,
on chain, join=by arr}
]
\foreach \i in {1,2,3}
\node [box] (n\i) {\i};
%
\path (n1) -- coordinate (aux) (n2);
\draw[arr] (aux) r-ud (n3.north);
\end{tikzpicture}
\end{document}
答案4
像这样:
代码(不使用任何库):
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[line width=3pt] (0,0) node[minimum height=2cm,minimum width=3cm,draw] (1) {\Huge \bfseries 1};
\draw[line width=3pt] (5,0) node[minimum height=2cm,minimum width=3cm,draw] (2) {\Huge \bfseries 2};
\draw[line width=3pt] (10,0) node[minimum height=2cm,minimum width=3cm,draw] (3) {\Huge \bfseries 3};
\draw[-latex,line width=3pt] (1) -- (2);
\draw[-latex,line width=3pt] (2) -- (3);
\draw[-latex,line width=3pt] (2.5,0)--(2.5,2)--(10,2)--(3);
\end{tikzpicture}
\end{document}