有没有办法使用该选项将代码(文本和命令)预先附加到所有节点rectangle
?
我发现这个帖子它解释了如何在每个节点之前执行命令,但这不允许我插入可见文本,至少在我尝试时不允许。
编辑:
\tikzset{
ell/.style={
% The shape:
ellipse,
%minimum width=6mm,
minimum height=6mm,
% The rest
inner sep=0,
draw=black,
fill=white,
font=\ttfamily},
skip loop/.style={to path={-- ++(0,#1) -| (\tikztotarget)}}
}
{
\tikzset{ell/.append style={text height=1.5ex,text depth=.25ex}}
}
\begin{tikzpicture}[
>=latex,thick,
/pgf/every decoration/.style={/tikz/sharp corners},
line join=round,line cap=round,
fuzzy/.style={decorate,
decoration={random steps,segment length=0.5mm,amplitude=0.15pt}},
]
\ttfamily
\begin{scope}[start chain=1 going below,
node distance=1mm,
every node/.append style={on chain, scale=0.7,
minimum width=5cm, align=center},
every ell node/.append style={
execute at begin node=(,
execute at end node=)},
scale=0.7,
]
\node [ell] (stmt01) {2. \verb|z = 20|};
\end{scope}
\end{tikzpicture}
答案1
欢迎光临!是的。
\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[every rectangle node/.append style={
execute at begin node=bla\space,
execute at end node=\space pft}]
\path node[rectangle] {hello} (0,-1) node[rectangle] {world};
\end{tikzpicture}
\end{document}
由于矩形是默认的,
\path node {hello} (0,-1) node {world};
产生相同的结果。
更新:至于您更新的问题,ell
不是形状而是样式。因此,every ell node/.append style=
您需要的是类似 的内容ell/.append style=
。
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{chains,shapes.geometric}
\begin{document}
\tikzset{
ell/.style={
% The shape:
ellipse,
%minimum width=6mm,
minimum height=6mm,
% The rest
inner sep=0,
draw=black,
fill=white,
font=\ttfamily},
skip loop/.style={to path={-- ++(0,#1) -| (\tikztotarget)}}
}
\tikzset{ell/.append style={text height=1.5ex,text depth=.25ex}}
\begin{tikzpicture}[
>=latex,thick,
/pgf/every decoration/.style={/tikz/sharp corners},
line join=round,line cap=round,
fuzzy/.style={decorate,
decoration={random steps,segment length=0.5mm,amplitude=0.15pt}},
]
\begin{scope}[start chain=1 going below,
node distance=1mm,
every node/.append style={on chain, scale=0.7,
minimum width=5cm, align=center},
ell/.append style={
execute at begin node=(,
execute at end node=)},
scale=0.7,node font=\ttfamily
]
\node [ell] (stmt01) {2. \verb|z = 20|};
\end{scope}
\end{tikzpicture}
\end{document}
或者你可以将内容附加到每个ellipse
节点
\begin{scope}[start chain=1 going below,
node distance=1mm,
every node/.append style={on chain, scale=0.7,
minimum width=5cm, align=center},
every ellipse node/.append style={
execute at begin node=(,
execute at end node=)},
scale=0.7,node font=\ttfamily
]
\node [ell] (stmt01) {2. \verb|z = 20|};
\end{scope}