如何在框图中添加像图片中那样的子图形?
我发现的示例代码对于这种情况并不完全有用:
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\begin{document}
\tikzstyle{block} = [draw, fill=white, rectangle,
minimum height=3em, minimum width=6em]
\tikzstyle{sum} = [draw, fill=white, circle, node distance=1cm]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]
我怎样才能以智能的方式连接这些块,使它们不依赖于坐标?
谢谢!
答案1
使用pic
图表可能会有帮助。
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{backgrounds,fit}
\begin{document}
\begin{tikzpicture}[pics/graph/.style={code={
\tikzset{graph/.cd,#1}
\begin{scope}[local bounding box=temp]
\draw[thick,red] plot[variable=\t,domain=0:0.9,samples=101,smooth]
({\t},{\pgfkeysvalueof{/tikz/graph/f}});
\edef\temp{\noexpand\path \pgfkeysvalueof{/tikz/graph/extra points};}
\temp
\end{scope}
\begin{scope}[on background layer,local bounding box=-bbox]
\path ([xshift=-2mm,yshift=-3mm]temp.south west)
([xshift=2mm,yshift=2mm]temp.north east);
\draw[-stealth] ([yshift=-1mm]temp.south west) --
([yshift=1mm]temp.north west) node[below
left]{\pgfkeysvalueof{/tikz/graph/ylabel}};
\draw[-stealth] (-0.1,0) -- (1,0)node[below,scale=0.7]{$t$};
\end{scope}
\node[fit=(-bbox),inner sep=0pt,draw](\pgfkeysvalueof{/tikz/graph/name}){};
}},/tikz/graph/.cd,extra
points/.initial={(0,0)},ylabel/.initial={$V$},f/.initial=\t,name/.initial={}]
\path pic{graph={f=1-0.5*\t,name=V1,ylabel=$V_1$,extra points={(0,1.1) (0,0)}}}
(0,-3)pic{graph={f=0.5+0.5*\t,name=V2,ylabel=$V_2$}};
\draw (V1.east) -- ++ (1,0) node[right,minimum width=1cm,draw] (a)
{$\vphantom{\beta}\alpha$}
(V2.east) -- ++ (1,0) node[right,minimum width=1cm,draw](b){$\beta$};
\path (a) -- (b) node[midway,right=1.5cm,circle,draw](p){$+$};
\draw[-stealth] (a)-| (p) (b) -| (p) (p.east) -- ++ (1,0) node[above
right]{$V_\mathrm{out}=\alpha V_1+\beta V_2$};
\end{tikzpicture}
\end{document}