有没有办法只用一行 TikZ 来绘制这个图表?
这是用
\node (A) [draw] {$h(t)$};
\draw (A.west) +(-1,0) circle (2pt) node [left] {$x(t)$} -- (A);
\draw (A.east) -- +(1,0) circle (2pt) node [right] {$y(t)=h(t)*x(t)$};
但是,我正在寻找一种方法来用一行代码来优化它(当前代码相当冗余)。这是我的尝试
\draw (0,0) circle (2pt) node [left] {$x(t)$} -- ++(1,0) node [draw,right] {$h(t)$} -- +(1,0) circle (2pt) node [right] {$y(t)=h(t)*x(t)$};
这就产生了:
显然,它不起作用,因为路径刚好从 (A.west) 出发并撞击盒子。
答案1
下面演示的两个选项均会产生以下结果:
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\begin{document}
% first option
\begin{tikzpicture}
\draw (0,0) node[left] {$x(t)$} circle[radius=2pt] -- node[draw,fill=white]{$h(t)$} (3,0) circle[radius=2pt] node[right] {$y(t) = h(t) \ast x(t)$};
\end{tikzpicture}
% second option
\begin{tikzpicture} % four lines just to easier see what happens, you can write it in one
\draw (0,0) circle[radius=2pt] -- (3,0) circle[radius=2pt]
node[pos=0,left] {$x(t)$}
node[midway,draw,fill=white]{$h(t)$}
node[pos=1,right] {$y(t) = h(t) * x(t)$};
\end{tikzpicture}
\end{document}
还有一个稍微不同的方法:
\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw node (a) [draw] {$h(t)$} (a.west) -- ++(-1,0) node[left] {$x(t)$} circle[radius=2pt] (a.east) -- ++(1,0) node[right] {$y(t)=h(t)*x(t)$} circle[radius=2pt];
\end{tikzpicture}
\end{document}