我创建了一个框图,但我不知道如何调整一些距离。
\documentclass[tikz, convert = false]{standalone}
\usepackage[utf8]{inputenx}% http://ctan.org/pkg/inputenx
% Euler for math | Palatino for rm | Helvetica for ss | Courier for tt
\renewcommand{\rmdefault}{ppl}% rm
\linespread{1.05}% Palatino needs more leading
\usepackage[scaled]{helvet}% ss // http://ctan.org/pkg/helvet
\usepackage{courier}% tt // http://ctan.org/pkg/courier
\usepackage{eulervm} % http://ctan.org/pkg/eulervm
% a better implementation of the euler package (not in gwTeX)
\normalfont%
\usepackage[T1]{fontenc}% http://ctan.org/pkg/fontenc
\usepackage{textcomp}% http://ctan.org/pkg/textcomp
\usetikzlibrary{shapes, arrows}
\begin{document}
\tikzstyle{block} = [draw, rectangle, minimum height = 2em, minimum width = 3em]
\tikzstyle{sum} = [draw, circle, node distance = 1.25cm]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\begin{tikzpicture}[auto, node distance = 2cm]
\node[input, name = input] {};
\node[sum, right of = input] (sum) {};
\node[sum, right of = sum] (s2) {};
\node[block, right of = s2, font = \scriptsize] (G) {$\frac{K}{Js + a}$};
\node[block, right of = G, font = \scriptsize] (H) {$\frac{1}{s}$};
\node[block, below of = G, font = \scriptsize] (F) {$K_f$};
\draw[-latex] (G) -- node[name = u] {} (H);
\draw[-latex] (u) |- (F);
\draw[-latex] (F) -| node[pos = 0.99] {$-$} node[pos = 1.105] {$+$} (s2);
\node[output, right of = H] (Y) {};
\draw[-latex] (input) -- node[font = \scriptsize] {$X$} (sum);
\draw[-latex] (sum) -- (s2);
\draw[-latex] (s2) -- (G);
\coordinate[below of = F, name = empty] {};
\draw[-latex] (H) -- node[name = Y, font = \scriptsize] {$Y$} (Y);
\draw (Y) |- (empty);
\draw[-latex] (empty) -| node[pos = 0.99] {$-$} node[pos = 1.05] {$+$} (sum);
\end{tikzpicture}
\end{document}
上面的代码产生
- 由于存在大量浪费的空间,我想减小反馈回路和 K_f 之间的距离。
- 我怎样才能将块 G 置于 s2 和 H 之间?
答案1
对于 1.,您必须empty
正确放置坐标。替换
\coordinate[below of = F, name = empty] {};
和
\coordinate[below = 0.2cm of F, name = empty] {};
适当更改0.2cm
。还使用positioning
库并使用= of
语法而不是of =
定位。这解决了您的第二个问题。
\documentclass[tikz, convert = false,border=10pt]{standalone}
\usepackage[utf8]{inputenx}% http://ctan.org/pkg/inputenx
% Euler for math | Palatino for rm | Helvetica for ss | Courier for tt
\renewcommand{\rmdefault}{ppl}% rm
\linespread{1.05}% Palatino needs more leading
\usepackage[scaled]{helvet}% ss // http://ctan.org/pkg/helvet
\usepackage{courier}% tt // http://ctan.org/pkg/courier
\usepackage{eulervm} % http://ctan.org/pkg/eulervm
% a better implementation of the euler package (not in gwTeX)
\normalfont%
\usepackage[T1]{fontenc}% http://ctan.org/pkg/fontenc
\usepackage{textcomp}% http://ctan.org/pkg/textcomp
\usetikzlibrary{shapes, arrows,positioning}
\begin{document}
\tikzset{block/.style = {draw, rectangle, minimum height = 2em, minimum width = 3em},
sum/.style = {draw, circle},
input/.style = {coordinate},
output/.style = {coordinate}
}
\begin{tikzpicture}[auto, node distance = 2cm]
\node[input, name = input] {};
\node[sum, right = of input] (sum) {};
\node[sum, right = of sum] (s2) {};
\node[block, right = of s2, font = \scriptsize] (G) {$\frac{K}{Js + a}$};
\node[block, right = of G, font = \scriptsize] (H) {$\frac{1}{s}$};
\node[block, below = of G, font = \scriptsize] (F) {$K_f$};
\draw[-latex] (G) -- node[name = u] {} (H);
\draw[-latex] (u) |- (F);
\draw[-latex] (F) -| node[pos = 0.99] {$-$} node[pos = 1.105] {$+$} (s2);
\node[output, right = of H] (Y) {};
\draw[-latex] (input) -- node[font = \scriptsize] {$X$} (sum);
\draw[-latex] (sum) -- (s2);
\draw[-latex] (s2) -- (G);
\coordinate[below = 0.2cm of F, name = empty] {};
\draw[-latex] (H) -- node[name = Y, font = \scriptsize] {$Y$} (Y);
\draw (Y) |- (empty);
\draw[-latex] (empty) -| node[pos = 0.99] {$-$} node[pos = 1.08] {$+$} (sum);
\end{tikzpicture}
\end{document}
答案2
一个(不太优雅的)PSTricks 解决方案:
\documentclass{article}
\usepackage{pstricks-add}
\begin{document}
\begin{pspicture}(8.5,2.5)
\psset{unit = 0.5, linecap = 1}
\pnodes{P}(0,4)(3,4)(6,4)(9,4)(11,4)(13,4)(15,4)(17,4)(15,0)(3,0)(11,1.5)(9,1.5)(6,1.5)
\pscircle(P1){0.3}
\uput[135](P1){$+$}
\uput[225](P1){$-$}
\pscircle(P2){0.3}
\uput[135](P2){$+$}
\uput[225](P2){$-$}
\pcline[linestyle = none, offset = 9pt](P0)(P1)
\ncput{$X$}
\ncline[linecap = 2, nodesep = 4pt]{->}{P0}{P1}
\ncline[nodesep = 4pt]{->}{P1}{P2}
\ncline[nodesepA = 4pt, nodesepB = 14.5pt]{->}{P2}{P3}
\rput(P3){\psframebox{$\frac{K}{Js + a}$}}
\ncline[nodesepA = 14.5pt, nodesepB = 7pt]{->}{P3}{P5}
\rput(P5){\psframebox{$\frac{1}{s}$}}
\ncline[nodesepA = 7pt]{->}{P5}{P7}
\uput[90](P6){$Y$}
\psline(P6)(P8)(P9)
\ncline[nodesepB = 4pt]{->}{P9}{P1}
\psline(P4)(P10)
\ncline[nodesepB = 10.5pt]{->}{P10}{P11}
\rput(P11){\psframebox{$K_{f}$}}
\ncline[nodesepA = 10.5pt]{P11}{P12}
\ncline[nodesepB = 4pt]{->}{P12}{P2}
\end{pspicture}
\end{document}
答案3
您还可以使用schemabloc
包可以更紧凑地描述框图。它也是高度可配置的。
但它是用法语描述的。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{schemabloc}
\begin{document}
\begin{tikzpicture}
\sbEntree{X}
\sbComp*{C1}{X} \sbRelier[X]{X}{C1}
\sbComp{C2}{C1} \sbRelier{C1}{C2}
\sbBlocL{F}{$\frac{K}{J\cdot s+a}$}{C2}
\sbBlocL[6]{int}{$\frac{1}{s}$}{F}
\sbSortie[6]{Y}{int} \sbRelier[Y]{int}{Y}
\sbDecaleNoeudy{F}{R}
\sbBlocr[-2]{R}{$K_f$}{R} \sbRelieryx{F-int}{R}
\sbRelierxy{R}{C2}
\sbRenvoi[6]{int-Y}{C1}{text}
\end{tikzpicture}
\end{document}
另一种风格:
\begin{tikzpicture}
\sbEntree{X}
\sbComph*{C1}{X} \sbRelier[X]{X}{C1}
\sbComp*{C2}{C1} \sbRelier{C1}{C2}
\sbBlocL{F}{$\frac{K}{J\cdot s+a}$}{C2}
{
\sbStyleBloc{fill=yellow!30,text=blue,align=center}
\sbBlocL[6]{int}{$\frac{1}{s}$}{F}
}
\sbSortie[6]{Y}{int} \sbRelier[Y]{int}{Y}
\sbDecaleNoeudy{F}{R}
{\sbStyleBloc{fill=red!30,text=purple,align=center}
\sbBlocr[-2]{R}{$K_f$}{R}
}
\sbRelieryx{F-int}{R}
\sbRelierxy{R}{C2}
\sbRenvoi[-4]{int-Y-1}{C1}{text}
\end{tikzpicture}
答案4
对于这种呈现规则分布的模式来说,matrix
节点是有帮助的。
您定义column sep
和,row sep
这意味着节点边界之间的空间。并将节点写成tabular
或(最后一行之后array
除外)。如果您需要更改两个特定列之间的距离,请使用而不是和来更改两个特定行之间的距离。\\
&[distance increment]
&
\\[row increment]
\documentclass[tikz, convert = false,border=10pt]{standalone}
\usepackage[utf8]{inputenx}% http://ctan.org/pkg/inputenx
% Euler for math | Palatino for rm | Helvetica for ss | Courier for tt
\renewcommand{\rmdefault}{ppl}% rm
\linespread{1.05}% Palatino needs more leading
\usepackage[scaled]{helvet}% ss // http://ctan.org/pkg/helvet
\usepackage{courier}% tt // http://ctan.org/pkg/courier
\usepackage{eulervm} % http://ctan.org/pkg/eulervm
% a better implementation of the euler package (not in gwTeX)
\normalfont%
\usepackage[T1]{fontenc}% http://ctan.org/pkg/fontenc
\usepackage{textcomp}% http://ctan.org/pkg/textcomp
\usetikzlibrary{shapes, arrows,positioning}
\begin{document}
\tikzset{block/.style = {draw, rectangle, minimum height = 2em, minimum width = 3em},
sum/.style = {draw, circle, label={[font=\scriptsize, inner sep=0pt]135:$+$},label={[font=\scriptsize, inner sep=0pt]225:$-$}},
input/.style = {coordinate},
output/.style = {coordinate},
aux/.style = {coordinate}
}
\begin{tikzpicture}[auto, node distance = 2cm]
\matrix (schema) [column sep=0.5cm, row sep=0.5cm]
{ \node[input, name = input] {};
&[0.5cm] \node[sum] (sum) {};
& \node[sum] (s2) {};
& \node[block, font = \scriptsize] (G) {$\frac{K}{Js + a}$};
&\node[aux] (GH) {};
&\node[block, font = \scriptsize] (H) {$\frac{1}{s}$};
&\node[aux] (HY) {};
&\node[output] (Y) {}; \\
&
&
& \node[block, font = \scriptsize] (F) {$K_f$};
& & & \\
& \node[aux] (fb1) {}; & & & \node[aux] (fb2) {}; \\};
\draw[-latex] (input) -- node[above,font=\scriptsize]{$X$} (sum);
\draw[-latex] (sum) -- (s2);
\draw[-latex] (s2) -- (G);
\draw[-latex] (G) -- (H);
\draw[-latex] (H)--node[above,font=\scriptsize] {$Y$} (Y);
\draw[-latex] (GH)|- (F);
\draw[-latex] (F)-|(s2);
\draw[-latex] (HY)|- (fb1)--(sum);
\end{tikzpicture}
\end{document}