我想将 tikz 使用的坐标元组存储在 pgfkeys 变量中。在下面的 MWE 中,我想将元组传递(0.5,0.5)
给命令并将其存储在变量中\position
:
\documentclass{article}
\usepackage{tikz,pgfkeys}
\usetikzlibrary{calc}
\pgfkeys{
/absolutenode/.is family, /absolutenode,
default/.style = {},
position/.store in = \position,
}
\newcommand\absolutenode[2][]{%
\pgfkeys{/absolutenode, default, #1}%
\tikz[remember picture,overlay,x=\paperwidth,y=\paperheight]{%
\node[anchor=center,inner sep=0pt] at ($(current page.south west)+\position$) {#2};
}
}
\begin{document}
\absolutenode[position=(0.5,0.5)]{Test}
\end{document}
但是元组中的逗号似乎是问题所在。我该如何修复它?
答案1
正如@gernot提到的,您需要用括号将坐标括起来。但根据我的发现,这还不起作用,但如果您还使用shift而不是使用,它确实有效calc
。
\documentclass{article}
\usepackage{tikz,pgfkeys}
\pgfkeys{
/absolutenode/.is family, /absolutenode,
default/.style = {},
position/.store in = \position,
}
\newcommand\absolutenode[2][]{%
\pgfkeys{/absolutenode, default, #1}%
\tikz[remember picture,overlay,x=\paperwidth,y=\paperheight]{%
\node[anchor=center,inner sep=0pt] at ([shift={\position}]current page.south
west) {#2};
}
}
\begin{document}
\absolutenode[position={(0.5,0.5)}]{Test}
\end{document}