我想用 pgf 3.0.0 绘制一个带有框、加法、乘法、分割的简单框图。
我对目前的结果非常满意,但我无法固定(用箭头)或标记图中的节点。
此外,我还希望在每个端点和起点处都画一个小圆圈,就像“in o-->|something|--o out”一样,并画一个实心圆点来表示分支节点。以下是 MWE:
\documentclass[tikz]{standalone}
\usetikzlibrary{graphs}
\begin{document}
\newcommand{\mult}{
\tikz[x=3mm,y=3mm] \draw[red] (0,0) -- (1,1) (0,1) -- (1,0);
}
\begin{tikzpicture}[
every pin edge/.style={<-},
pin distance=4,
vh path/.style = {to path={|- (\tikztotarget)}},
block/.style = {
rectangle, minimum size=6mm,draw},
mul/.style = {draw,circle,inner sep=0},
shape = coordinate
]
\graph [grow right sep, branch down=2, simple,fresh nodes] {
/ -> "$\int$"[block] -- / -> [vh path]
{[nodes={yshift=1cm}]
"\mult"[mul,pin=above:$\frac{1}{2}$] -- "$\eta |\cdot|^2$"[block] -- /,
"\mult"[mul,pin=above:$\frac{1}{2}$] -- something[block] -- / % does not work as intended
};
};
\end{tikzpicture}
\end{document}
以下是 MWE 的图片:
我知道的替代方案是使用矩阵、相对定位和手动放置。但是,我喜欢图形方法,我希望它能发挥作用。欢迎提出进一步的建议。
答案1
tikzpicture
问题在于您使用的环境选项中shape=coordinate
。这会将默认形状设置为坐标,这意味着当绘制节点并且形状不是明确地给定时,将使用坐标并忽略文本。
every pin/.style={shape=rectangle}
一个解决方案是在键中使用tikzpicture
:
\documentclass[tikz, border=5]{standalone}
\usetikzlibrary{graphs}
\begin{document}
\newcommand{\mult}{\tikz[x=3mm,y=3mm]\draw[red] (0,0) -- (1,1) (0,1) -- (1,0);}
\begin{tikzpicture}
[ %every pin edge/.style={arrows=<-},
pin distance=4,
vh path/.style={to path={|- (\tikztotarget)}},
block/.style={rectangle, minimum size=6mm,draw},
mul/.style={draw,circle,inner sep=0},
shape=coordinate,
every pin/.style={shape=rectangle}
]
\graph [grow right sep, branch down=2, simple,fresh nodes] {
/ -> "$\int$"[block] -- / -> [vh path]
{[nodes={yshift=1cm}]
"\mult"[mul,pin=above:$\frac{1}{2}$] -- "$\eta |\cdot|^2$"[block] -- /,
"\mult"[mul,pin=above:$\frac{1}{2}$] -- something[block] -- /
};
};
\end{tikzpicture}
\end{document}