我正在尝试使用带有多个参数的 tikzset。我尝试按照说明操作这里,但它不起作用(错误是
错误:\pgfkeys@temp 定义中的参数编号非法
)这是我的乳胶代码
\documentclass[tikz]{standalone}
%\tikzset{newbox/.style={draw, rectangle, inner sep = 1.5em, fill=white,
% label={[align=left,shift={(-12ex,3.5ex)}]south east:#1,north
% west:{\color{red} #2}}} n args={2}}
\tikzset{oldbox/.style={draw, rectangle, inner sep = 1.5em, fill=white,
label={[align=left,shift={(-12ex,3.5ex)}]south east:{\color{blue}#1}}}}
\begin{document}
\begin{tikzpicture}
\node [oldbox={$\alpha$}] at (-1,-1) (working) {};
%\node [newbox={a}{b}] at (0,0) (fails) {};
\end{tikzpicture}
\end{document}
这将编译,但当我取消注释时,它会中断。我想newbox
接受 2 个参数。请注意,我对 tikz 并不特别熟练 - 似乎有多种方法可以做每件事,所以我学到了一些零零碎碎的东西,但从来没有时间认真尝试理解整个手册。
答案1
这是更精确的定义。
\documentclass[tikz]{standalone}
\tikzset{newbox/.style n args=2{draw, rectangle, inner sep = 1.5em, fill=white,
label={[align=left,anchor=south east]south west:#1},
label={[align=left,anchor=north east,text=blue]north west:#2}},
%
oldbox/.style={draw, rectangle, inner sep = 1.5em, fill=white,
label={[align=left,anchor=south east,text=blue]south west:#1}}
}
\begin{document}
\begin{tikzpicture}
\node [oldbox={$\alpha$}] at (-2,-2) (working) {};
\node [newbox={a}{b}] at (0,0) (fails) {};
\end{tikzpicture}
\end{document}
答案2
你追求的是style 2 args
,而不仅仅只是style
。
\documentclass[tikz,border=3mm]{standalone}
\tikzset{newbox/.style 2 args={
draw, rectangle, inner sep = 1.5em, fill=white,
label={[blue,align=left,shift={(-12ex,5.5ex)}]south east:#1},
label={[red]north west:{#2}}
},
oldbox/.style={draw, rectangle, inner sep = 1.5em, fill=white,
label={[align=left,shift={(-12ex,3.5ex)}]south east:{\color{blue}#1}}}}
\begin{document}
\begin{tikzpicture}
\node [oldbox={$\alpha$}] at (-1,-1) (working) {};
\node [newbox={a}{b}] at (0,0) (fails) {};
\end{tikzpicture}
\end{document}