这是我第一次尝试绘制 Tikz 中的任何内容,所以请耐心等待:
我正在尝试绘制一个 DSP 算法的简单流程图,但是我无法正确绘制它所包含的循环返回。正如您在下面的代码示例中看到的,我只能通过在中心节点的左侧定义一个节点并从底部向该节点绘制箭头,然后从该节点向顶部绘制箭头,才能不使返回箭头与图中的块相交。
有没有办法用一个箭头连接底部和顶部节点并使其穿过该节点(或者更好的是,自动使其避免与现有块相交)?
需要注意的是:
我无法消除箭头起点和终点之间的间隙,如能得到任何帮助我将不胜感激。
另外,由于我在框文本中使用了换行符,框之间的间距不合适,所以我只能手动调整间距。有没有更好的方法?
\documentclass[12pt, a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning,calc}
\begin{document}
\tikzstyle{block} = [draw, rectangle,
minimum height=3em, minimum width=20em]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]
\begin{tikzpicture}[auto, node distance=2cm,>=latex']
\node [input, name=input] {};
\node [block, below of=input, align=left] (reseter)
{$Betrag\ von\ X_{w}^{(i)}(mS, \omega)\ zur\ddot{u}cksetzen:$\\
$\hat{X}_{w}^{(i)}(mS, \omega)=|Y_{w}(mS, \omega)|\cdot
e^{j\angle X_{w}^{(i)}(mS, \omega)}$};
\node [block, below= 1cm of reseter, align=left] (estimator)
{$Signalsch\ddot{a}tzung\ von\ X_{w}^{(i)}(mS, \omega):$\\
$x^{(i+1)}(n) = \frac {\displaystyle \sum \limits_{m=-\infty}^{\infty}
w (mS-n) \cdot \hat x_w^{(i)} (mS,n) }
{\displaystyle \sum \limits_{m=-\infty}^{\infty} w^2 (mS-n)}$};
\node [output, below=1.2cm of estimator] (output){};
\draw [->] (input) -- node {$x^{(i)}(n)$} (reseter);
\draw [->] (reseter) -- node [name=X] {$\hat{X}_{w}^{(i)}(mS, \omega)$} (estimator);
\draw [->] (estimator) -- node {$x^{(i+1)}(n)$} (output);
\node [above = 0.5cm of output] (fbs) {};
\node [below = 0.5cm of input] (fbe) {};
\node [left=5cm of X] (fb) {};
\draw [->] (fbs) -| (fb);
\draw [->] (fb) |- (fbe);
\end{tikzpicture}
\end{document}
答案1
此代码会自动将块间隔开足够远,以允许文本在它们之间移动。可以通过在节点之间增加inner sep
或来增加此空间outer sep
。我确实不得不留出一点空间来清除左侧的空间(reseter)
。
注意:许多更改纯粹是风格上的。below of=
或 本身并没有什么问题name=
,我只是不喜欢使用它们。
\documentclass[12pt, a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning,calc}
\begin{document}
\tikzset{input/.style=coordinate}
\tikzset{output/.style=coordinate}
\tikzset{block/.style={draw, rectangle,
minimum height=3em,
minimum width=20em}}
\tikzset{pinstyle/.style={pin edge={to-,thin,black}}}
\begin{tikzpicture}[auto, node distance=2cm,>=latex']
\node (input) [input] {};
\node (fbe) [below right] at (input.south) {$x^{(i)}(n)$};
\node (reseter) [block, below, align=left] at (fbe.south west)
{$Betrag\ von\ X_{w}^{(i)}(mS, \omega)\ zur\ddot{u}cksetzen:$\\
$\hat{X}_{w}^{(i)}(mS, \omega)=|Y_{w}(mS, \omega)|\cdot
e^{j\angle X_{w}^{(i)}(mS, \omega)}$};
\node (X) [below right] at (reseter.south) {$\hat{X}_{w}^{(i)}(mS, \omega)$};
\node (estimator) [block, below, align=left] at (X.south west)
{$Signalsch\ddot{a}tzung\ von\ X_{w}^{(i)}(mS, \omega):$\\
$x^{(i+1)}(n) = \frac {\displaystyle \sum \limits_{m=-\infty}^{\infty}
w (mS-n) \cdot \hat x_w^{(i)} (mS,n) }
{\displaystyle \sum \limits_{m=-\infty}^{\infty} w^2 (mS-n)}$};
\node (fbs) [below right] at (estimator.south) {$x^{(i+1)}(n)$};
\node (output) [output, below] at (fbs.south west) {};
\draw [->] (input) -- (reseter);
\draw [->] (reseter) -- (estimator);
\draw [->] (estimator) -- (output);
\coordinate (fb) at ($(estimator.west)+(-1em,0)$);
\draw [->] (fbs) -| (fb) |- (fbe);
\end{tikzpicture}
\end{document}