我正在尝试创建一个框图,但在放置箭头方面遇到了挑战。此外,我不确定如何合并这个触发块。有人能帮我用 \arrows 绘制这个吗?
我拥有的
\documentclass[border=0.2cm]{standalone}
% More defined colors
\usepackage[dvipsnames]{xcolor}
% Required package
\usepackage{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, node distance=0.5cm,>=latex', scale=0.8, transform shape]
\node [input, name=input] {};
\node [sum, right=1.5cm of input, line width=0.25mm,] (sum) {};
\node [draw=black,
minimum width=2cm,
minimum height=1.2cm,
right=1.5cm of sum] (1) {1};
\node [draw=black,
minimum width=2cm,
minimum height=1.2cm,
right=1.5cm of 1] (2) {2};
\node [draw=black,
minimum width=2cm,
minimum height=1.2cm,
right=1.5cm of 2] (3){2};
\node [draw=black,
minimum width=2cm,
minimum height=1.2cm,
above right =1cm and -0.5cm of 1] (4){4};
\node [draw=black,
minimum width=2cm,
minimum height=1.2cm,
right =1.3cm of 4] (6){6};
\node [draw=black,
minimum width=2cm,
minimum height=1.2cm,
above = 1cm of 3] (5){};
\node [minimum width=1mm,
line width=0.25mm,
minimum height=1.4cm, output, right=1 cm of 3] (y) {};
\draw [draw,->, line width=0.25mm] (input) -- node {r} (sum);
\draw [->,line width=0.25mm] (sum) -- (1);
\draw [->,line width=0.25mm] (1) -- (2);
\draw [->,line width=0.25mm] (2) -- (3);
\draw [line width=0.25mm] (3) -- (y);
\draw [->,line width=0.25mm] (6.west) --(4.east);
\draw [->, line width=0.25mm] (y) -- ++ (0,-1.5) -| node [pos=0.98, right] {$-$} (sum.south);
\draw[line width=0.25mm,->] (4.south) -- ++ (0,-0.5) -| (1.north);
\draw[line width=0.25mm,->] (4.south)+(0,-0.5) -| (2.north west);
\draw [->,line width=0.25mm] (y) |- node [pos=0.98, left] {} (5.east);
\end{tikzpicture}
\end{document}
答案1
这是一种从您的代码开始并对其进行一些修改以提高清晰度的方法,可以介绍您错过的大部分内容。一些备注:
tikzlibraries + tikzset
此图表不需要大多数内容。我没有检查该\tikzset
语句,它可能重复后面的内容。
拥有自己的风格
我将多余的\node
和格式移到\draw
了开头,分别称为blk
和ln
。这在大多数情况下使代码更易于阅读(重构)。
指定边框锚点
如果N
是节点名称,则极“坐标”N.20
位于节点形状(恰好是矩形)上,距节点中心测量 +20 度。
这样,您就可以沿着形状“移动”箭头。
因为你使用数字作为节点名称,2.130
看起来5.-20
很奇特,但仍然是边界锚点。例如,它不是2.130mm
。请参阅最近的讨论和 pgfmanual 链接。
我把这些线条涂成红色,以便更清楚地看到它们。
缺少连接器(橙色)
非常简单,定义曲流的中间节点,结合您的方法和极坐标符号中的边界锚点。
节点 5 内的“图像”
我建议将内部绘制为\pic
,并用其替换所述节点\pic
,请参阅在 pfgmanual 中。然后,您就可以更清楚地区分该块的内部结构和外部连接。在我看来,绘制草图毫无用处(在这种情况下,作为一名电子工程师)。
\documentclass[border=0.2cm]{standalone}
% More defined colors
%\usepackage[dvipsnames]{xcolor}% <<< not needed here
% Required package
\usepackage{tikz}
%\usetikzlibrary{arrows,shapes,backgrounds,patterns,fadings,matrix,arrows,calc,
% intersections,decorations.markings,
% positioning,external,arrows.meta}% <<< not needed here
\usetikzlibrary{arrows,positioning,arrows.meta}
% ... leave uncehcked as is ...............
\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}[% moving blk and ln here
auto,
node distance=0.5cm,
>=latex',
scale=0.8,
transform shape,
blk/.style={draw=black,
minimum width=2cm,
minimum height=1.2cm},
ln/.style={line width=0.25mm},
]
% ~~~ blocks ~~~~~~~~~~~~~~~~~~~~~~~~
\node [input, name=input] {};
\node [sum, right=1.5cm of input, line width=0.25mm,] (sum) {};
\node [blk,right=1.5cm of sum] (1) {1};
\node [blk,right=1.5cm of 1] (2) {2};
\node [blk,right=1.5cm of 2] (3) {3?};
\node [blk, above right =1cm
and -0.5cm of 1] (4){4};
\node [blk, right =1.3cm of 4] (6){6};
\node [blk,above = 1cm of 3] (5){(5)}; % <<<
% ~~~ sum at input ~~~~~~~~~~~~~~~~~~~
\node [minimum width=1mm,
line width=0.25mm,
minimum height=1.4cm, output, right=1 cm of 3] (y) {};
%~~~ connectors ~~~~~~~~~~~~~~~~~~~
\draw [->,ln] (input) -- node {r} (sum);
\draw [->,ln] (sum) -- (1);
\draw [->,ln] (1) -- (2);
\draw [->,ln] (2) -- (3);
\draw [ln] (3) -- (y);
\draw [->,ln] (6.west) --(4.east);
\draw [->,ln] (y) -- ++ (0,-1.5) -| node [pos=0.98, right] {$-$} (sum.south);
\draw[->,ln] (4.south) -- ++ (0,-0.5) -| (1.north);
\draw[->,ln,red] (4.south)+(0,-0.5) -| (2.130); % <<<
\draw [->,ln,red] (y) |- node [pos=0.98, left] {} (5.20);% <<<
% ~~~ new lines ~~~
\draw[->,ln,orange] (2.east) -- ++(.5,0) |- ++(0,.9) -- ++(3.5,0) |- (5.-20);
\draw[->,ln,orange] (2.50) |-++(3,.6) -- (5.south);
\end{tikzpicture}
\end{document}
答案2
- 作为起点,我使用了我的附录中经过修改的代码回答。
- 由于我不清楚块中的开关结构
sensor3
,因此开关按我的观点绘制,因为它具有逻辑结构。 - 所有代码变化(与启动 MWE 相比)都是市场变化。
\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
calc, chains,
ext.paths.ortho, % defined in the tikz-ext package,
% https://ctan.org/pkg/tikz-ext?lang=en
positioning,
quotes}
\tikzset{
node distance = 8mm and 6mm,
start chain = A going right,
arr/.style = {-Straight Barb},
Car/.style = {-{Circle[open]}}, % new
block/.style = {draw, thick, minimum height=11mm, minimum width=22mm},
dot/.style = {suspend join,
circle, draw, fill, inner sep=1.2pt, node contents={}},
sum/.style = {circle, draw, thick, inner sep=2pt, node contents={\huge +}}
}
\makeatletter
\tikzset{suspend join/.code={\def\tikz@after@path{}}}
\makeatother
\begin{document}
\begin{tikzpicture}
% main branch
\begin{scope}[nodes = {on chain=A, join=by arr}]
\coordinate (in);
\node[sum]; % A-2
\node[block] {$A(s)$};
\node[block] {$B(s)$};
\node[block] {$C(s)$};
\node[dot, join=by -];
\node[block] {$D(s)$};
\node[dot, join=by -]; % A-7,
\coordinate (out);
\end{scope}
\path[draw=none] (A-8) to["$x$"] (out);
% top branch
\node [block, above=of A-4] (sensor1) {$E(s)$};
\node [block, above=of A-5] (sensor2) {$F(s)$};
\node [block, above=of A-7] (sensor3) {};
% switch (NEW)
\coordinate (s-out) at ([xshift=-2mm] sensor3.center); % <---
\coordinate[right=2mm] (s-in1) at ([yshift=+2mm] sensor3.center); % <---
\coordinate[right=2mm] (s-in2) at ([yshift=-2mm] sensor3.center); % <---
\coordinate (s-in1a) at (s-in1 -| sensor3.east); % <---
\coordinate (s-in2a) at (s-in2 -| sensor3.east);; % <---
%
\draw[Car] (sensor3.west) -- (s-out); % <---
\draw[Car] (s-in1a) -- (s-in1); % <---
\draw[Car] (s-in2a) -- (s-in2); % <---
%
\draw[thick] (s-out) -- (s-in1); % <---
\draw[dashed] (s-in1 -| sensor3.south) -- (sensor3.south); % <---
% arrows not considered in the join macro
\draw[arr] (sensor3) edge (sensor2)
(sensor2) edge (sensor1);
\draw[arr] ([xshift=-3mm] sensor1.south) |-| (A-3);
\draw[arr] ([xshift=+3mm] sensor1.south) |-| ([xshift=-3mm] A-5.north);
\draw[arr] ([xshift=+3mm] A-5.north) |-| (sensor3);
\draw[arr] (A-6) |- ([yshift=-6mm] sensor3.south)
r-rl (s-in2a); % changes
\draw[arr] (A-8) |- (s-in1a); % changes
\draw[->] (A-8) r-du (A-2);
\end{tikzpicture}
\end{document}
- 这就是你所追求的吗?
- 如果不是,请澄清您的问题!