TeX - LaTeX Asked by superruzafa on March 17, 2021
I’m trying to understand how the expansion of a pgfextra
which in turn is inside an append after command
is done. My idea is to read some value from a pgf
key when the append after command
code is executed, but I’m afraid the code is being expanded on the style definition.
documentclass[12pt]{standalone}
usepackage{tikz}
usetikzlibrary{calc}
usetikzlibrary{arrows.meta}
begin{document}
begin{tikzpicture}
pgfkeys{
/my label/.initial=initial,
}
tikzset{my node/.style={
draw=red,
minimum size=1cm,
node contents=#1,
append after command={
pgfextra
draw [-Implies, double, shorten >=2ex] (tikzlastnode.south) -- +(0, -1cm);
path [use as bounding box] (tikzlastnode.south west) rectangle ($ (tikzlastnode.south west) + (0, -1cm) $);
pgftransformshift{pgfpoint{0pt}{-1.5cm}}
pgfnode{rectangle}{base}{pgfkeysvalueof{/my label}}{}{pgfusepath{discard}}
endpgfextra
}
}}
fill (-1, 1) [white] rectangle (1, -2);
node at (0, 0) [/my label=label, my node=1] {};
end{tikzpicture}
end{document}
What I get
vs what I’m trying to achieve
What I eventually want to do is to draw two nodes like the image from above that can be fully referenced later by only specifying one node, for example:
% this create a node with `name` and `node contents` K and a node below with `name` and `node contents` V.
% the argument V could be set here or read dynamically from a pgf key)
node [key=K, value=V]
draw [->] (K.north) -- +(0, 1);
draw [->] (V.south) -- +(0, -1);
Any way to achieve this or must I specify two nodes manually?
Apparently you want to solve your problem in a particular way, using the key system of tikz and pre- and post-expansions. I cannot contribute to this in any way.
Just in case you consider also other approaches: I suggest to use plain macros.
documentclass[border=2pt]{standalone}
usepackage{tikz}
usetikzlibrary{calc}
usetikzlibrary{arrows.meta}
% KeyValue[options for the upper node]{position}{name of upper node}{name of lower node}
newcommandKeyValue[4][]{%
node[draw=red,minimum size=1cm,#1] (#3) at (#2) {3};
draw[-Implies,double] (#3) -- +(0, -1cm) node[below,inner sep=1pt](#4){#4};
}
begin{document}
begin{tikzpicture}
KeyValue{0,0}{1}{label}
draw [->] (1.north) -- +(0, 1);
draw [->] (label.south) -- +(0, -1);
end{tikzpicture}
end{document}
Answered by gernot on March 17, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP