如何访问节点是否“在网格中”

如何访问节点是否“在网格中”

我想要访问存储on grid选项是否激活的变量,来计算我的几个距离\pgfdeclareshape

我做了一些研究。我读到如何从 pgfkeys 样式元素中提取值访问 TikZ 中的样式属性? 。然后,我猜测的值on grid存储在中tikz@lib@ignore@size。我尝试通过中提到的想法提取值访问 TikZ 中的样式属性?

我的 MWE 如下:

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{positioning}

\makeatletter
\def\getongrid{\tikz@lib@ignore@size}
\makeatother

\begin{document}
\begin{tikzpicture}[node distance=3mm]
  \node [] (n1) {1};
  \node [right=of n1] (n2) {\getongrid};
\end{tikzpicture}
\end{document}

但是我收到一个错误:

Undefined control sequence.
\getongrid ->\tikz@lib@ignore@size 

l.17   \node [right=of n1] (n2) {\getongrid
                                           };

我怎样才能解决这个问题?

供您参考,我得到了以下跟踪trace-pgfkeys.sty

[trace-pgfkeys]-+ \pgfkeysdefaultpath : /tikz
[trace-pgfkeys]-+ Key/value list: (on grid/.is if=tikz@lib@ignore@size)
[trace-pgfkeys]-+ Current key-value: (#1)
[trace-pgfkeys]-+ \pgfkeyscurrentkey (given): on grid/.is if
[trace-pgfkeys]-> \pgfkeyscurrentkey : /tikz/on grid/.is if
[trace-pgfkeys]-+ \pgfkeyscurrentvalue : (tikz@lib@ignore@size)
[trace-pgfkeys]-+ \pgfkeyscurrentpath (/tikz/on grid)
[trace-pgfkeys]-+ \pgfkeyscurrentname (.is if)
[trace-pgfkeys]-+ Executing all handlers.
[trace-pgfkeys]--+ Executing handler.
[trace-pgfkeys]--> Handler: /handlers/.is if
[trace-pgfkeys]--+ \pgfkeysdefaultpath : (/tikz/)
[trace-pgfkeys]--+ Key/value list: (\pgfkeyscurrentpath /.code=\pgfkeys@handle@
boolean {tikz@lib@ignore@size}{##1}, \pgfkeyscurrentpath /.default=true)
[trace-pgfkeys]---+ Current key-value: (#1)
[trace-pgfkeys]---+ \pgfkeyscurrentkey (given): /tikz/on grid/.code
[trace-pgfkeys]---> \pgfkeyscurrentkey : /tikz/on grid/.code
[trace-pgfkeys]---+ \pgfkeyscurrentvalue : (\pgfkeys@handle@boolean {tikz@lib@i
gnore@size}{##1})
[trace-pgfkeys]---+ \pgfkeyscurrentpath (/tikz/on grid)
[trace-pgfkeys]---+ \pgfkeyscurrentname (.code)
[trace-pgfkeys]---+ Executing all handlers.
[trace-pgfkeys]----+ Executing handler.
[trace-pgfkeys]----> Handler: /handlers/.code
[trace-pgfkeys]----+ Execution finished.
[trace-pgfkeys]---+ Current key-value: (#1)
[trace-pgfkeys]---+ \pgfkeyscurrentkey (given): /tikz/on grid/.default
[trace-pgfkeys]---> \pgfkeyscurrentkey : /tikz/on grid/.default
[trace-pgfkeys]---+ \pgfkeyscurrentvalue : (true)
[trace-pgfkeys]---+ \pgfkeyscurrentpath (/tikz/on grid)
[trace-pgfkeys]---+ \pgfkeyscurrentname (.default)
[trace-pgfkeys]---+ Executing all handlers.
[trace-pgfkeys]----+ Executing handler.
[trace-pgfkeys]----> Handler: /handlers/.default
[trace-pgfkeys]----+ Execution finished.
[trace-pgfkeys]---+ Last key processed.
[trace-pgfkeys]--+ Execution finished.
[trace-pgfkeys]-+ Last key processed.

答案1

内部变量是一个\if...开关:

\iftikz@lib@ignore@size <true case> \else <false case> \fi

示例文件:

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{positioning}

\makeatletter
\def\getongrid{\iftikz@lib@ignore@size true\else false\fi}
\makeatother

\begin{document}
\begin{tikzpicture}[node distance=3mm]
  \node [] (n1) {1};
  \node [right=of n1] (n2) {\getongrid};
\end{tikzpicture}
\end{document}

结果

相关内容