單線:線 -> 節點 -> 線

單線:線 -> 節點 -> 線

有沒有辦法只用 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}

相關內容