你好,我想知道如何在 Latex 中绘制框图。我是该程序的初学者,所以到目前为止,我对此还算比较熟悉。我想创建
只是没有粗线或灰色块。我无法连接所有东西并将块并联或串联。到目前为止,我只能做一个非常简单的。请问我能得到一些帮助吗,谢谢。
\tikzset{
block/.style={
draw,
fill=blue!20,
rectangle,
minimum height=3em,
minimum width=6em
},
sum/.style={
draw,
fill=blue!20,
circle,
},
input/.style={coordinate},
output/.style={coordinate},
pinstyle/.style={
pin edge={to-,thin,black}
}
}
% The block diagram code is probably more verbose than necessary
\begin{center}
\begin{tikzpicture}[auto,>=latex']
% We start by placing the blocks
\node [input, name=input] {};
\node [sum, right = of input] (sum) {};
\node [block, right = of sum] (controller) {$K_d$};
\node [block, right = of controller, pin={[pinstyle]above:$f(t)$},
node distance=3cm] (system) {$G(s)$};
% We draw an edge between the controller and system block to
% calculate the coordinate u. We need it to place the measurement block.
\draw [->] (controller) -- node[name=u] {} (system);
\node [output, right =of system] (output) {};
%\node [block, below of=u] (measurements) {Measurements};
% Once the nodes are placed, connecting them is easy.
\draw [draw,->] (input) -- node {$r$} (sum);
\draw [->] (sum) -- node {} (controller);
\draw [->] (system) -- node [name=y] {$x$}(output);
\draw [->] (y) -- ++(0,-2cm) -| node[pos=0.99] {}
node [near end] {} (sum);
\end{tikzpicture}
答案1
这是一种方法。它使用链,您可以使用 当场更改边缘标签[el=<label>]
。通过在必要时“升级”样式,我们可以避免手动添加所有连接。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,chains}
\begin{document}
\begin{center}
\begin{tikzpicture}[auto,>=Latex,
cnode/.style={},
block/.style={cnode,
draw,
fill=blue!20,
rectangle,
minimum height=3em,
minimum width=6em
},
tblock/.style={block,minimum width=2em},
sum/.style={cnode,
draw,
fill=blue!20,
circle,
},
input/.style={coordinate,cnode},
output/.style={coordinate,cnode},
arj/.style={-Latex,semithick}]
%
\begin{scope}[start chain=R going right,
cnode/.append style={join=by arj,on chain},
node distance=2.5em,
arj/.append style={edge label=\pgfkeysvalueof{/tikz/el}},
el/.initial={}]
\path node[input]{}
[el={$r$}]
node[tblock,alias=Nbar]{$\overline{N}$}
[el={}]
node[sum,label=above left:{$+$},label=below right:{$-$}]{}
[el={$u$}]
node[tblock,alias=B]{$B$}
[el={},arj/.append style={very thick}]
node[sum,label=above left:{$+$},label=below right:{$+$}]{}
[el={$\dot x$}]
node[tblock,alias=o]{$1/s$}
[el={$x$}]
node[tblock,alias=C,xshift=3em]{$C$}
[el={$y$}]
node[output]{};
\end{scope}
%
\begin{scope}[start chain=D going below,
cnode/.append style={on chain},
node distance=2.5em]
\chainin (o);
\node[tblock,alias=A]{$A$};
\node[tblock,alias=K]{$K$};
\end{scope}
%
\path (o) -- (C) coordinate[pos=1/3] (oC1) coordinate[pos=2/3] (oC2);
\draw[arj] (K) -| (R-2);
\tikzset{arj/.append style={very thick}}
\draw[arj] (A) -| (R-5);
\draw[arj] (oC1) |- (A);
\draw[arj] (oC2) |- (K);
\end{tikzpicture}
\end{center}
\end{document}
答案2
另一种方法是:
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
chains,
positioning,
quotes}
\begin{document}
\begin{tikzpicture}[
node distance = 4mm and 6mm,
start chain = going right,
base/.style = {draw, fill=blue!20},
block/.style = {base, minimum height=2em, minimum width=3em},
sum/.style = {base, circle, node contents={}},
arr/.style = {ultra thick, -{Latex[length=5pt, width=6pt]}},
every edge/.style = {draw, -Latex},
]
% We start by placing the blocks in chain
\begin{scope}[nodes={on chain}]
\coordinate (in);
\node (n1) [block] {$\bar{N}$};
\node (n2) [sum];
\node (n3) [block] {$B$};
\node (n4) [sum];
\node (n5) [block] {$1/s$};
\coordinate (n6);
\coordinate (n7);
\node (n8) [block] {$C$};
\coordinate (out);
\end{scope}
%
\path (in) edge["$r$"] (n1)
(n1) edge[near end,"+"] (n2)
(n2) edge["$u$"] (n3)
(n3) edge[arr,near end,"+"] (n4)
(n4) edge[arr,"$\dot{\mathbf{x}}$"] (n5)
(n5) edge[arr,"$\mathbf{x}$"] (n8)
(n8) edge[arr,"$\mathbf{y}$"] (out);
% Block in backloops
\node (n11) [block, below=of n5] {$A$};
\node (n12) [block, below=of n11] {$K$};
%
\draw[arr] (n6) |- (n11);
\draw[arr] (n11) -| (n4) node[below right] {$+$};
\draw[arr] (n7) |- (n12);
\draw[-Latex] (n12) -| (n2) node[below right] {$-$};
\end{tikzpicture}
\end{document}
答案3
这是在 ctan 上使用框图包的建议。
https://ctan.org/pkg/schemabloc
\documentclass{article}
\usepackage{schemabloc}
\begin{document}
\begin{tikzpicture}
\sbEntree{E}
\sbBlocL{B1}{$\overline{N}$}{E}
\sbRelier[$r$]{E}{B1}
\sbComp*{C1}{B1}
\sbRelier{B1}{C1}
\sbStyleBloc{blue,very thick,fill=yellow,text=red}%
\sbBloc{B2}{$B$}{C1}
\sbRelier[$u$]{C1}{B2}
\sbSumb*{C2}{B2}
\sbRelier{B2}{C2}
\sbBloc{B3}{$\frac{1}{s}$}{C2}
\sbRelier[$\dot{x}$]{C2}{B3}
\sbBloc[6]{B4}{$C$}{B3}
\sbRelier[$x$]{B3}{B4}
\sbSortie[4]{Y}{B4}
\sbStyleBloc{very thick,fill=green,text=blue}%
\sbRelier[$y$]{B4}{Y}
\sbDecaleNoeudy{B3}{R3}
\sbStyleLien{ultra thick, red}
\sbBlocr[-1.5]{R3}{$A$}{R3}
\sbRelieryx{B3-B4}{R3}
\sbRelierxy{R3}{C2}
\sbDecaleNoeudy[9]{B3}{R4}
\sbBlocr[-1.5]{R4}{$K$}{R4}
\sbRelieryx{B3-B4}{R4}
\sbRelierxy{R4}{C1}
\end{tikzpicture}