您好,图形文本爱好者 :) 我正在尝试在 TikZ 中绘制尽可能接近以下图表的图表:
我正在使用 dsp TikZ 库,我认为我的尝试正朝着正确的方向发展;然而,有几件事我没有正确设置,正如你从 MWE 中看到的那样
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{dsp,chains}
\begin{document}
\begin{tikzpicture}
% Blocks and nodes
\node[dspnodeopen,dsp/label=below] (ns) {$v(t)$};
\node[dspmultiplier,left=of ns,fill=gray] (mic) {};
\node[dspadder,left=of mic,left=1.5cm] (add) {};
\node[coordinate,left=of add,left=2.35cm] (fp1) {};
\node[dspfilter,above=of fp1,above=1.5cm] (gain) {$G$};
\node[coordinate,above=of gain,above=1.5cm] (fp2) {};
\node[dspnodefull,right=of fp2,right=2.55cm] (adnode) {$u(t)$};
\node[dspfilter,right=of gain,right=1.15cm] (adfilt) {$\hat{F}$};
\node[dspsquare,right=of fp2,right=4cm] (ls) {};
\node[dspfilter,right=of gain,right=4cm] (feedback) {F};
\node[dspnodefull,left=of add] (afupd1) {};
\node[coordinate,above=of afupd1,above=1cm] (afupd2) {};
\node[coordinate,right=of adfilt,above=3.5cm,right=0.5cm] (afupd3) {};
% Connections
\draw[dspconn] (ns) -- (mic);
\draw[dspline] (mic) -- node[midway,below=0.09cm] {$y(t)$} (add);
\draw[dspline] (add) -- node[midway,below] {$d[t,\hat{\mathbf{f}}(t)]$} (fp1);
\draw[dspline,dashed] (afupd1) -- (afupd2);
\draw[dspconn,dashed] (afupd2) -- (afupd3);
\draw[dspconn] (fp1) -- (gain);
\draw[dspline] (gain) -- (fp2);
\draw[dspline] (fp2) -- (adnode);
\draw[dspline] (adnode) -- (ls);
\draw[dspconn] (adnode) -- (adfilt);
\draw[dspconn] (adfilt) -- node[midway,right] {$\hat{y}[t |\hat{\mathbf{f}}(t)]$} (add);
\draw[dspconn] (ls) -- (feedback);
\draw[dspconn] (feedback) -- (mic);
\end{tikzpicture}
\end{document}
我的 MWE 如下:
也就是说,我无法正确重现以下内容:
- 麦克风和扬声器符号(灰色块)
- 过滤块的垂直对齐
- 虚线斜线的正确定位(它应该在中间用 \hat{F} 切割块)
- 曲线与 F 滤镜块相连
- 加法器中的加号和减号。
有人愿意帮助这位可怜的 TikZ 用户吗?
谢谢 ;)
答案1
一种可能性是:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{dsp,chains,calc,shapes.geometric}
\begin{document}
\begin{tikzpicture}
% Blocks and nodes
\node[dspnodeopen,dsp/label=below]
(ns) {$v(t)$};
\node[left=of ns,fill=gray,circle,draw]
(mic) {};
\draw ([yshift=8pt]mic.east) -- ([yshift=-8pt]mic.east);
\node[dspadder,left=of mic,left=1.5cm,label={above right:$-$},label={below right:$+$}]
(add) {};
\node[coordinate,left=of add,left=2.35cm]
(fp1) {};
\node[dspfilter,minimum height=2cm,above=of fp1,above=1.5cm]
(gain) {$G$};
\node[coordinate,above=of gain,above=1.5cm]
(fp2) {};
\node[dspnodefull,right=of fp2,right=2.55cm]
(adnode) {$u(t)$};
\node[dspfilter,minimum height=2cm,right=of gain,right=1.15cm]
(adfilt) {$\hat{F}$};
\node[draw,right= 4cm of fp2,fill=gray,trapezium,shape border rotate=90,shape border uses incircle]
(ls) {};
\draw ([yshift=-10pt]ls.west) -- ([yshift=10pt]ls.west);
\node[dspfilter,minimum height=2cm,right=of gain,right=4cm]
(feedback) {F};
\node[dspnodefull,left=of add]
(afupd1) {};
\node[coordinate,above=of afupd1,above=1cm]
(afupd2) {};
\coordinate (aux) at ([yshift=-4pt]adfilt.center);
% Connections
\draw[dspconn] (ns) -- (mic);
\draw[dspconn] (mic) -- node[midway,below=0.09cm] {$y(t)$} (add);
\draw[dspline] (add) -- node[midway,below] {$d[t,\hat{\mathbf{f}}(t)]$} (fp1);
\draw[dspline,dashed] (afupd1) -- (afupd2);
\draw[dspconn,dashed] (afupd2) -- ( $ (afupd2)!2.7cm!(aux) $ );
\draw[dspconn] (fp1) -- (gain);
\draw[dspline] (gain) -- (fp2);
\draw[dspline] (fp2) -- (adnode);
\draw[dspconn] (adnode) -- (ls);
\draw[dspconn] (adnode) -- (adfilt);
\draw[dspconn] (adfilt) -- node[midway,right] {$\hat{y}[t |\hat{\mathbf{f}}(t)]$} (add);
\draw[dspconn] (ls) to[out=0,in=90] (feedback);
\draw[dspconn] (feedback) to[out=-90,in=30] ([yshift=3pt]mic.east);
\end{tikzpicture}
\end{document}
具体问题的答案:
使用标准 TikZ 形状。例如,扬声器只是
trapezium
从shapes.geometric
库中旋转而来。无需额外调整。您可以使用节点
minimum height
的标准密钥dspfilter
。我放置了一个辅助坐标
adfilt.center
(稍微向下移动以防止线与“F”重叠),然后使用了来自( $ (<name1>)!<length>!(<name2>) $ )
calc 库的。您可以使用
to[out=<angle1>,in=<angle2>]
。我将所需的标签放置到
add
节点上。
在评论中,提到了从外部文件包含图形时剪切标签的一些问题。在这种情况下,我建议您使用该类standalone
将您的图像生成为单独的 pdf 文件,然后可以使用标准机制轻松地将其包含在您的文档中\includegraphics
;graphicx
您可以使用border
独立选项来控制图形周围的填充,以防万一:
例如,将以下内容保存为MyImage.tex
:
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{dsp,chains,calc,shapes.geometric}
\begin{document}
\begin{tikzpicture}
% Blocks and nodes
\node[dspnodeopen,dsp/label=below]
(ns) {$v(t)$};
\node[left=of ns,fill=gray,circle,draw]
(mic) {};
\draw ([yshift=8pt]mic.east) -- ([yshift=-8pt]mic.east);
\node[dspadder,left=of mic,left=1.5cm,label={above right:$-$},label={below right:$+$}]
(add) {};
\node[coordinate,left=of add,left=2.35cm]
(fp1) {};
\node[dspfilter,minimum height=2cm,above=of fp1,above=1.5cm]
(gain) {$G$};
\node[coordinate,above=of gain,above=1.5cm]
(fp2) {};
\node[dspnodefull,right=of fp2,right=2.55cm]
(adnode) {$u(t)$};
\node[dspfilter,minimum height=2cm,right=of gain,right=1.15cm]
(adfilt) {$\hat{F}$};
\node[draw,right= 4cm of fp2,fill=gray,trapezium,shape border rotate=90,shape border uses incircle]
(ls) {};
\draw ([yshift=-10pt]ls.west) -- ([yshift=10pt]ls.west);
\node[dspfilter,minimum height=2cm,right=of gain,right=4cm]
(feedback) {F};
\node[dspnodefull,left=of add]
(afupd1) {};
\node[coordinate,above=of afupd1,above=1cm]
(afupd2) {};
\coordinate (aux) at ([yshift=-4pt]adfilt.center);
% Connections
\draw[dspconn] (ns) -- (mic);
\draw[dspconn] (mic) -- node[midway,below=0.09cm] {$y(t)$} (add);
\draw[dspline] (add) -- node[midway,below] {$d[t,\hat{\mathbf{f}}(t)]$} (fp1);
\draw[dspline,dashed] (afupd1) -- (afupd2);
\draw[dspconn,dashed] (afupd2) -- ( $ (afupd2)!2.7cm!(aux) $ );
\draw[dspconn] (fp1) -- (gain);
\draw[dspline] (gain) -- (fp2);
\draw[dspline] (fp2) -- (adnode);
\draw[dspconn] (adnode) -- (ls);
\draw[dspconn] (adnode) -- (adfilt);
\draw[dspconn] (adfilt) -- node[midway,right] {$\hat{y}[t |\hat{\mathbf{f}}(t)]$} (add);
\draw[dspconn] (ls) to[out=0,in=90] (feedback);
\draw[dspconn] (feedback) to[out=-90,in=30] ([yshift=3pt]mic.east);
\end{tikzpicture}
\end{document}
处理完毕后,pdflatex
您将得到MyImage.pdf
如下文件(图形周围的灰色区域不是生成的 pdf 的一部分):
然后你可以使用
\usepackage{graphicx}% in preamble
\includegraphics{MyImage}% in document body
在您的.tex
文件中包含图像。您可以使用键控制各个边距boder
(请参阅独立文档)。
答案2
我采用了 Gonzalo 的代码,并对其进行了调整以解决问题 2(过滤器的大小)。
该dsp
库包含一个\dspfilterwidth
设置过滤器块宽度的命令(这就是为什么它们似乎与minimum width
和配合不好minimum height
,至少在我的测试中)。
因此我首先让它变得稍微更适合一些,然后扩展样式dspfilter
以获得过滤器的特定高度:
\renewcommand{\dspfilterwidth}{8mm}
\newcommand{\dspfilterheight}{1.8cm}
\tikzset{dspfilter/.append style = {minimum height=\dspfilterheight}}
不幸的是,这会弄乱很多块的间距,因此我检查了节点代码并对其进行了调整,以便块能够排列整齐,即使您自己选择了不同的常量。
我还在最右边的过滤器中添加了数学模式符号:如果您希望它与原始图表相匹配,它应该$F$
代替纯文本。F
这是我调整后的代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{dsp,chains,calc,shapes.geometric}
\begin{document}
\begin{tikzpicture}
\renewcommand{\dspfilterwidth}{8mm}
\newcommand{\dspfilterheight}{1.8cm}
\tikzset{dspfilter/.append style = {minimum height=\dspfilterheight}}
\newcommand{\dspvspace}{1.2cm}
% Blocks and nodes
\node[dspnodeopen, dsp/label=below]
(ns) {$v(t)$};
\node[left=of ns, fill=gray, circle, draw]
(mic) {};
\draw ([yshift=8pt] mic.east) -- ([yshift=-8pt] mic.east);
\node[dspadder, left=of mic, left=2.35cm, label={above right:$-$}, label={below right:$+$}]
(add) {};
\node[coordinate, left=of add, left=1.8cm]
(fp1) {};
\node[dspfilter, above=of fp1, above=\dspvspace]
(gain) {$G$};
\node[coordinate, above=of gain, above=\dspvspace]
(fp2) {$fp2$};
\node[dspnodefull, above=of add, above=2*\dspvspace+\dspfilterheight-0.5*\dspoperatordiameter-\dspblocklinewidth]
(adnode) {$u(t)$};
\node[dspfilter, above=of add, above=\dspvspace-0.5*\dspoperatordiameter]
(adfilt) {$\hat{F}$};
\node[draw, above=of mic, above=2*\dspvspace+\dspfilterheight-\dspblocklinewidth-0.4cm, fill=gray, trapezium, shape border rotate=90, shape border uses incircle]
(ls) {};
\draw ([yshift=-10pt] ls.west) -- ([yshift=10pt] ls.west);
\node[dspfilter, above=of ns, above=\dspvspace]
(feedback) {$F$};
\node[dspnodefull, left=of add, left=0.8cm]
(afupd1) {};
\node[coordinate, above=of afupd1, above=\dspvspace]
(afupd2) {};
\coordinate (aux) at (adfilt.center);
% Connections
\draw[dspconn] (ns) -- (mic);
\draw[dspconn] (mic) -- node[midway,below=0.09cm] {$y(t)$} (add);
\draw[dspline] (add) -- node[midway,below] {$d[t,\hat{\mathbf{f}}(t)]$} (fp1);
\draw[dspline,dashed] (afupd1) -- (afupd2);
\draw[dspconn,dashed] (afupd2) -- ( $ (afupd2)!3cm!(aux) $ );
\draw[dspconn] (fp1) -- (gain);
\draw[dspline] (gain) -- (fp2);
\draw[dspline] (fp2) -- (adnode);
\draw[dspconn] (adnode) -- (ls);
\draw[dspconn] (adnode) -- (adfilt);
\draw[dspconn] (adfilt) -- node[midway,right] {$\hat{y}[t |\hat{\mathbf{f}}(t)]$} (add);
\draw[dspconn] (ls) to[out=0,in=90] (feedback);
\draw[dspconn] (feedback) to[out=-90,in=30] ([yshift=3pt]mic.east);
\end{tikzpicture}
\end{document}
其结果如下: