使用下面的代码生成下面的图形作为更复杂图形的一部分。
\documentclass{beamer}
\setbeamertemplate{navigation symbols}{}
\usepackage{tikz}
\begin{document}
\begin{minipage}{\textwidth}
\begin{tikzpicture}[scale=.5, transform shape]
\node [thin, black] (0,0) (origin){}
([shift={(0.:1.2)}]origin.center) node (txtu){}
([shift={(-65.:4.)}]origin.center) node (txtd){}
([shift={(180.:7.)}]txtd.center) node (txtds){}
([shift={(180.:5.8)}]txtds.center) node (txtdt){}
([shift={(-90.:.4)}]origin.center) node (od){}
([shift={(180.:5.)}]od.center) node (odsens){}
([shift={(-90.:9.8)}]odsens.center) node (odsensd){}
([shift={(0.:.12)}]od.center) node (odr){}
([shift={(0.:3.)}]od.center) node (odrr){}
([shift={(180.:.12)}]od.center) node (odl){}
([shift={(180.:1.)}]od.center) node (odll){}
([shift={(-90.:.26)}]odrr.center) node (odrrd){}
([shift={(-90.:.12)}]odll.center) node (odllc){}
([shift={(-90.:.24)}]odll.center) node (odlld){}
;
\draw[thick, purple!60!black, top color=red, bottom color=red, middle color=red!60, opacity=.4] (odr.center) -- ([shift={(90.:.4)}]odr.center) .. controls (40:1.2) and (140:1.2) .. ([shift={(90.:.4)}]odl.center) -- (odl.center);
\draw[thick, purple!60!black, top color=red, bottom color=red, middle color=red!60, opacity=.4] ([shift={(180.:.02)}]odr.center) -- (odrr.center) -- (odrrd.center) -- (odlld.center) -- (odll.center) -- ([shift={(0.:.02)}]odl.center);
\end{tikzpicture}
\end{minipage}
\end{document}
是否可以向下重复此绘图 2 次并将它们连接在一起形成一个单元,看起来像下面的绘图。
答案1
一种方法是定义一个宏,\MyComponents
绘制组件,然后绘制连接它们的线。
代码:
\documentclass{beamer}
\setbeamertemplate{navigation symbols}{}
\usepackage{tikz}
\newcommand*{\MyComponents}[2][]{%
%% #1 = drawing options
%% #2 = name of node
\begin{scope}[scale=.5, transform shape, #1]
\node [thin, black] (0,0) (origin) {}
([shift={(0.:1.2)}]origin.center) node (txtu){}
([shift={(-65.:4.)}]origin.center) node (txtd){}
([shift={(180.:7.)}]txtd.center) node (txtds){}
([shift={(180.:5.8)}]txtds.center) node (txtdt){}
([shift={(-90.:.4)}]origin.center) node (od){}
([shift={(180.:5.)}]od.center) node (odsens){}
([shift={(-90.:9.8)}]odsens.center) node (odsensd){}
([shift={(0.:.12)}]od.center) node (odr){}
([shift={(0.:3.)}]od.center) node (odrr){}
([shift={(180.:.12)}]od.center) node (odl){}
([shift={(180.:1.)}]od.center) node (odll){}
([shift={(-90.:.26)}]odrr.center) node (odrrd){}
([shift={(-90.:.12)}]odll.center) node (odllc){}
([shift={(-90.:.24)}]odll.center) node (odlld){}
;
\draw[thick, purple!60!black, top color=red, bottom color=red, middle color=red!60, opacity=.4] (odr.center) -- ([shift={(90.:.4)}]odr.center) .. controls (40:1.2) and (140:1.2) .. ([shift={(90.:.4)}]odl.center) -- (odl.center);
\draw[thick, purple!60!black, top color=red, bottom color=red, middle color=red!60, opacity=.4] ([shift={(180.:.02)}]odr.center) -- (odrr.center) -- (odrrd.center) -- (odlld.center) -- (odll.center) -- ([shift={(0.:.02)}]odl.center);
\coordinate (#2 Top) at (odll.center);
\coordinate (#2 Bot) at (odlld.center);
\end{scope}
}
\begin{document}
\begin{tikzpicture}
\MyComponents{Node 1}
\MyComponents[yshift=-1.5cm]{Node 2}
\MyComponents[yshift=-3.0cm]{Node 3}
\draw [blue, line width=3pt] ([yshift=0.5pt]Node 1 Top) -- ([yshift=-0.5pt]Node 3 Bot);
\end{tikzpicture}%
\end{document}