我想创建一组样式,其中每个样式都可以选择将内容放在节点内或外面。我设法做到了这一点,但我还希望能够针对一种给定的风格强制一种行为。
因此,我尝试创建一个强制执行此行为的函数,但是它会在 3 个级别上创建 tikz 样式的嵌套...并且不幸的是,我找不到如何在该设置中引用参数:因为#1
引用了第一级的参数,并且##1
引用了第二级,我期望###1
引用第三级...但它无法编译。
梅威瑟:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
my global style/.style={
mynode/.style={fill=red,rounded corners=1mm},
my default label style/.style={
above, font=\tiny
},
add content/.style={
%% By default, adds the content at the end of the node
execute at begin node=##1,
%% But we would like to be able to force this behaviour later:
%label={[my global style, my default label style] ##1},
},
%% /!\ uncomment these lines, it will break:
% force content in label/.style={
% add content/.style={
% % ##1 should be the argument of "add content" and ###1 should be the argument of "add content"
% label={[my global style, my default label style,##1] ###1},
% },
% },
% force content in label/.default={},
}
]
\node[my global style, mynode, add content=Abc] {};
%% Goal: make this work
% \node[force content in label, add content=Abc] at (2,0) {};
% \node[force content in label=below, add content=Abc] at (4,0) {};
\end{tikzpicture}
\end{document}